/dpt/ - Daily Programming Thread

Previous thread: What are you working on, Sup Forums?

Other urls found in this thread:

devernay.free.fr/hacks/chip8/C8TECH10.HTM)
en.wikipedia.org/wiki/Null_Object_pattern#Java
twitter.com/NSFWRedditVideo

First for F*

give an example usage of a factory

your mom

F* is pretty cool

I wonder if a merge between Ocaml and F# can happen

I want a merge between F# and D

python shitters are terrible """"""""programmers""""""""

Reminder that Rust is the best language and everything else is a sad joke by comparison.

>dependent types automatically make a language good for systems programming even if it's still garbage collected
Who started this meme?

>No himegoto

Shit thread.

KILL YOURSELF FALSE FLAGGING RETARD FAG SHILL

Im making a chat program that connects to a centralized server

not an argument

This 3bh

kill yourself

cool
make sure to market it to the normies as some new technology (aka front end to irc)

no thank you x

FUCK YOU YOU'RE A FUCKING PATHETIC PIECE OF SHIT YOUR LIFE IS SHIT

Who are you quoting?

*kiss lick wet heart emoji*

and_then is literally just writing >>= with lambdas in Haskell instead of using comprehensions or do notation. So no, Rust doesn't have a satisfying equivalent.

It has try! for Option and Result but it's not using the fact that they're monads to work.

>being baited this easily
Are you 12 or something?

Yes, i just need a logo and name ;^)


The point is to just make a really simple protocol that is easy to code clients for, and have a server that anyone may connect to.

>le epin bait xD
get a life kid

>get a life kid

And while do notation may have been designed around the IO monad, it's useful for far more. It's okay to like a language while admitting it has faults.

Literally what is websockets with socket.io....

People who talk about Idris. It's neat, but it's just Haskell with dependent types.

Do notation is literally the default mode.
x;
y
is the same thing as haskell's
do x
y
Hakelltards on suicide watch yet again.

You have a severely limited "understanding" of monads.

The suicide hotline is ready for you. Don't do it, just call them!

Learn me a haskell
Learn you a haskell
For a few more monads
real good

haskell:

x = (\x -> asjkfi >>= (\y -> asf x, y))

equivalent to

[ asf x, y | x

trying to compile this program that is supposed to allow me to flash an ARM microcontroller

I don't really know what exactly it's supposed to do, Adafruit just linked to it as a Linux alternative to the popular NXP "Flash Magic"

what the fuck does this mean when I try to compile it?


nate@nate-Aspire-V5-571:~/Desktop/lpc$ make -f Makefile clean all
rm -f adprog.o lpcprog.o lpcterm.o lpc21isp
gcc -Wall -static -c -o adprog.o adprog.c
gcc -Wall -static -c -o lpcprog.o lpcprog.c
gcc -Wall -static -c -o lpcterm.o lpcterm.c
gcc -Wall -static -o lpc21isp lpc21isp.c adprog.o lpcprog.o lpcterm.o

Those are just the compilation commands that the makefile is running. It's successful.

so... how do I run it?

>-static
>with -c
ebin

More specifically it uses statically linked dependencies (but i don't see it linking any outside libs) and names the resulting executable lpc2lisp. The first command makes sure that any pre-cached object files are removed before compiling in case you have no clobber set (meaning preventing a program from overwriting an already existing file).

rust:
x = asfgf();
y = f(asjkfi())();
asf(x, y);

asfgf().and_then(|x| asfkfi().and_then(|y| asf(x, y)))

Equivalent to
asfgf().iter().zip(f(asjkfi())).map(|(x, y)| asf(x, y));

no, not equivalent because in haskell that works with any monad

Have you tried killing yourself yet? It would increase the average IQ on Earth by at least 5 points.

So does it in rust. Don't kill yourself just yet alright? The suicide hotline people are there for you.

where's the love user

r-rude

>implying Rust can do that transformation

you just said
>Equivalent to
>asfgf().iter().zip(f(asjkfi())).map(|(x, y)| asf(x, y));

so it doesn't work for any monad because not every monad has zip

There's more to monads than just IO.

Every iter has zip, retard. It's literally the same thing. Every iter has zip because of the way traits work.

>backpedaling at the speed of light

I'm not backpedaling, I've been saying that all along. You seem to think that do notation is equivalent to just writing imperative code, but that only applies if you're talking about IO which is essentially just sequencing operations with arbitrary effects.

look, i said that this
is equivalent to this
and now you're saying it's not that at all in rust

also HO functions are nice but do syntax & comprehensions for monads is much fucking nicer and the point of the argument

It is equivalent and you should move your butthurt over to ##haskell

/dpt/-chan, dai suki~

// Animal factory
Animal newAnimal (string animalName)
{
if ("Pig" == animalName)
return new Pig(); // Pig is private
else if ("Dog" == animalName)
return new Dog(); // Dog is private
}


// User can have a pig and a dog without knowing these types.
Animal pig = newAnimal("Pig");
Animal dog = newAnimal("Dog");

>what is websockets with socket.io
web shit

the c one is a bit innacurate m8ey

let newAnimal = function
| "Pig" -> new pig ()
| "Dog" -> new dog ()

>using a string instead of an enum

reading from a file

separation of concerns

an enum does mean a new type which add complexity

?

And?

The factory doesn't give a shit about I/O, so it shouldn't take a string. Converting the string to the enum (and providing an appropriate error) is something that should be done elsewhere.

Adding an enum defeats the purpose because they 're already subtypes
Read what I replied to

>elsewhere
What do you mean elsewhere?
When did I say where it is?
There's literally no good justification for why the given factory is better than that

how do i go from this to getting all of the matched groups in an array?

Hey guys, so I have these 2 modules that implement a plugin API (in C). The hosting application (everything running in the same address space) can pass messages from one module to another in the form of text strings. I'd like to use a more efficient communication method between my modules, so I figured I'd send from one module to the other a pointer to a function which they can later use as an alternative means of communication. The question is: how do I pass the address of the callback from one module to another using the text messaging interface and doing it in a standard, portable manner?

factory is about eliminating type complexity in favor of interface complexity. with an enum, you still have to create a new type that you will have to maintain which ruins the purpose of a factory.

I guess so. In that case, I would ensure that the factory isn't a partial function by returning 'animal option or something.

or the null object pattern.

Hey Sup Forums
I'm currently developing a chip-8 with SDL (may seem a bit 'much' but SDL is easy to use) and I've currently hit a wall.

I'm trying to implement this instruction:
Dxyn - DRW Vx, Vy, nibble
Display n-byte sprite starting at memory location I at (Vx, Vy), set VF = collision.

The interpreter reads n bytes from memory, starting at the address stored in I. These bytes are then displayed as sprites on screen at coordinates (Vx, Vy).
Sprites are XORed onto the existing screen. If this causes any pixels to be erased, VF is set to 1, otherwise it is set to 0.
If the sprite is positioned so part of it is outside the coordinates of the display, it wraps around to the opposite side of the screen.
See instruction 8xy3 for more information on XOR, and section 2.4, Display, for more information on the Chip-8 screen and sprites.

(devernay.free.fr/hacks/chip8/C8TECH10.HTM)

The problem is, I can't just manipulate the pixels directly since I'm scaling the screen

The function I have is slow, but it works in unit tests. I'm looking to see if there are any alternatives to just storing a separate set of pixels for this DRW function to use as a set of ints then just using bit shifts to get which pixels I should xor?
thx

Which is a horrible, horrible alternative especially if you're already in a functional language.

>null
>ever

I think I'm too retarded for programming.

i don't see how the language being functional or not is relevant at all, you only need ADTs for the null object pattern which has nothing to do with a null reference. it's time for /dpt/ to learn what is and how to abstraction.

Literally just use an option type

What is the "null object pattern", to you?

You are probably using some low level garbage like C# or Java

Learn it with Haskell and enjoy programming

I cringe at the interview questions which ask some inane question about Java, c#, etc, which never happens in Haskell or another functional langauge. Since it wasn't made in the 70s

>low level
>Java
these webshits should just leave Sup Forums forever

>which never happens in Haskell or another functional langauge
because you do literally nothing useful

The Haskell runtime runs it, the Haskell code just rearranges pure functions

>>low level
>not greentexting C#
kys

Java is low level when you compare it to Haskell

en.wikipedia.org/wiki/Null_Object_pattern#Java

an object with no side effects where the purpose actually is to replace a null reference.

Why the everloving fuck would you use this when you can use option?

kill yourself

>garbage like C#

yes, but not through F*. It could come around the same time as 1ML and be a joint effort between Microsoft and INRIA to stay relevant. Or maybe INRIA or Microsoft will just start "copying" features from each other in upcoming languages releases. I think that's more likely to happen from INRIA because Microsoft has already strayed away from it a ton in ways that would be hard to recover from (object system completely different, namespaces AND modules, etc.), so OCaml would introduce computation expressions, units of measure, quoted syntax, etc.
I like F* a lot, but I think its use cases are pretty limited when compared to other dependently typed languages
I don't think it has anything to do with systems programming but I still prefer it to Haskell
nigga wtf

...

here's the function in question
please don't laugh (pretty please)
void DRW_func(int n1, int n2, int nibble) { // since we have a scale we can't just XOR the sprite onto our drawing surface.
gObject* found = findGraphic(nibble); // findGraphic searches the graphic list for the address cpu.I. If found, returns the pointer
// if not, the address at cpu.I in the program is read for upto nibble bytes and pointer to the created graphic is returned.
int intersects = 0;
int x = cpu.v[n1], y = cpu.v[n2];
int posX = x/32, ofsX = x%32;

for (size_t i = 0; i < found->size; i++) {
// YES I KNOW THIS WON'T WRAP AROUND CORRECTLY YET. THAT'S NOT IMPORTANT RIGHT NOW
//tempRow just gets the pixel data we want.
unsigned int tempRow = (pixels[(y*2)+posX] (8-ofsX));
if (tempRow & found->data[i]) {
intersects = 1;
}

unsigned int pixResult = tempRow ^ found->data[i];
pixels[(y*2)+posX] = (pixResult >> ofsX) | (pixels[(y*2)+posX] & ((int)0xFFFFFFFF > (8-ofsX));
}

cpu.v[0xF] = intersects;
redraw();
}


I was using chars up until now, realized how stupid that was and so I switched to ints like 30 seconds ago but you get the idea.
Is there a faster way to implement this DRW function?

pajeet pls
.net is ass

i want FP fags and python shitters to leave

ignore the (int)0xFFFFFFFF please. That cast obviously doesn't belong

you still have to check your options ! options are like null references but safer since the check is unavoidable. null objects completly avoid the need to check.

maybe(Animal) a = newAnimal(...);
if ( some(a) )
Animal aa = a.unpack();
aa.sound();


vs

Animal a = newAnimal(...);
aa.sound();


no, seriously, buy a book on design pattern and abstraction techniques, there nothing more important in programming.

>.net is ass

It's great, though.

>benis dd | comp xd = drop 2 dd

>finally find out the address where Qemu ARM64 adds PCI devices
>the VGA PCI device doesn't assign a memory address to the BAR's so I can write to framebuffer
I feel like shooting shit up

A maybe type is literally an option type you dumbass
>if >unpack
Just a more verbose, less safe version of this:

a |> Option.bind (fun a -> a.sound())

>returning a "default" instead of explicitly making it an error to be handled
It may seem harmless there, but what if the class in question has a method that needs to return something useful? Return another default? Make another null object for the returned type?

It's not a good solution, it's literally a hack.

So my Python project suddenly started throwing an error saying "cannot set attribute", something related to tuple attributes, it didn't happen before so I guess it has to do with updating Python version from 3.4 to 3.5 or so, what gives? Why would a minor version break compatibility?

>he still hasn't realized