/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?


Previous Thread:

Other urls found in this thread:

okmij.org/ftp/Haskell/polyvariadic.html#polyvar-fn
golang.org/src/encoding/binary/binary.go#L158
twitter.com/SFWRedditGifs

First for Haskell

haskell is bad and you should FEEL bad!

>functions in his favorite programming language can only fave one argument

Top
Kek

Linear types can make imperative code pure.

>his language doesn't have MUH MONADS

Mercury is so pure, she will help you restore your anal virginity.

I don't know what that is, so I'm certain it's wrong.

They don't give you the composability or first class nature that monads have

Asking one more time:
Does anyone know how strong the Sup Forums API rules are enforced?
Especially the rule Do not make more than one request per second..

>hurr durr currying

Also
okmij.org/ftp/Haskell/polyvariadic.html#polyvar-fn

Monads kind of have two uses. The first would be sequential composition and the second would be standing in for linear types. Monads are great at doing the first thing, but I'd like to have the real thing when it comes to linear types as well.

>he's unable to explain what a monad is without using obscure mathematical terms
>he'll fail like the dozens other haskell devs who failed before him

can I just get a small, informal survey going? I just want to know if you are a professional, making a living off of your coding, a student hoping to become a pro, or just a hobbyist doing it for kicks. That's all. THanks!

POO

I'm working on a constant pool editor for java. Currently reading the class file is done, but saving it (data back to butes) still needs to get done.

I'm really fucking angry. I spent ages looking at an lg smart tv api for a project of mine and got everything all comfortable only for life to shit all over me because lg introduced a new messaging protocol recently.

Trying to go for my VMware vSphere Cert. Got my lab setup. I basically setup nested virtualization (ESXi Hosts running on VM's). Works ok, for a lab.

>and the second would be standing in for linear types
Not true, and linear values again force stuff on the language like strict ordering.

Which is faster?

String x="dicks";

or

String x=new String("dicks");

Friendly reminder compilers for almost every language should be able to evaluate pure functions at compile time.

First one. Allocating memory on the stack is just moving the stack pointer. Allocating on the heap is more complicated

it's impossible

this, fucking smug haskell tards

But what if a "pure" function isn't really pure?

Then it's not a pure function.

Monads force strict ordering you dunce.

>encoding/binary.Read can do it with a struct passed by interface{}, so there is no reason you why you can't do the same thing, applied by a slice of blank interfaces as []interface{}
then go read their implementations?
golang.org/src/encoding/binary/binary.go#L158

Not on the entire language and all its expressions which is the exact point

Not everything needs to be linear.

Making everything linear is better.

So use monads and do notation.

Monads force LIFO without insane workarounds.

What do you mean LIFO?

Create resource A
Create resource B
Destroy resource A
Destroy resource B

Last In, First Out.

RAII?

Is there any portable way to create structs at the runtime that are compatible with the ones created at compile time?

What's that got to do with monads in general?

What?

It doesn't have to do with monads in general, it has to do with using monads to approximate linearity.

They're contiguous

"resource aquisition is initialisation", but it's also a term for more stuff
like using smart pointers in C++ or similar (using constructors/destructors for acquiring and releasing resources in general)

That's FIFO you fucking inbred

RAII implies creating and destroying resources but not the other way around.

Who said anything about approximating linearity?
The argument was about someone who said "use linear types rather than monads"

Yes, I should have made it more clear that because that is ~not~ LIFO, monads struggle with it.

Because monads only approximate linearity.

Creating and destroying resources around a given block of code is what you'd call RAII

>Because monads only approximate linearity.
Nobody asked for linearity.

And you can get linear values from dependently typed monads

Where do you see any blocks of code in that post? RAII is really only relevant when you have panics or exceptions.

>They're contiguous
But there are stuff such as alignment that one should have in mind, as well as weird architectures and bitfields.

Between monads and linearity, linearity is the one that's actually useful. So you should be asking for it.

>Nobody asked for linearity.
Salty bitch. I already said monads are useful for composition, but linear types are better at sequencing (preventing aliasing).

>And you can get linear values from dependently typed monads
How so?

>RAII is really only relevant when you have panics or exceptions.
Not remotely true

>>>oh I guess they can APPROXIMATE linear values -heh-"
>>who asked for that

>Salty bitch

>>And you can get linear values from dependently typed monads
>How so?
You can create an arbitrary DSL and enforce arbitrary requirements with dependent typing - e.g. "don't refer to this var again"

>monads aren't useful
I can tell you don't use them

I swear Haskel fags are just as bad as idolfags. They won't stop harping about muh purity, muh purity. Just use slut functions like a real man, faggots!

It's probably not particularly monitored, but you really shouldn't exceed the 1 request per second rule. Who knows what Sup Forums is running on these days - it might be an even older model of a mac mini ever since Japanese moot took over.

>marry a slut function
>she fucks other men
cucked again ;_;

Holy shit, this language is unreadable. I'll never leave the comfiness of C-like languages.

idk but it's probably talking about the average rate like if you're making requests every half second constantly, but a short burst of a few requests (followed by a pause) is probably fine

I like it when haskellfags talk about how haskell is magically readable when it looks like an explosion in a syntax factory.

>not pump and dump

I presume the "problem" contained within this image is that the person is a female, but I assure you that 90% of all people in intro CS courses are this retarded. I could not believe just how incompetent some of my classmates were at even the most basic of concepts.

>Not remotely true
Otherwise, it's just garbage collection (i.e. you don't have to explicitly call a destructor). Without exceptions or panics, you can call a destructor. With them, you'd have to catch, call a destructor, and then rethrow. Gets hairy with a lot of resources. RAII solves this, but otherwise it's doing minimal work.

>You can create an arbitrary DSL and enforce arbitrary requirements with dependent typing - e.g. "don't refer to this var again"
Well, yes, if you encode a linear type theory in a metatheory then you get linear types. Monads have fuck all to do with that, though.

I get that you're a Haskell evangelist but please learn to accept that there are ivory towers even higher and purer than Haskell has to offer.

What's wrong with it? I get it's different to what you're used to

Maybe I should actually try it, but the syntax looks so awful to me that it discourages me from trying it.

>Otherwise, it's just garbage collection (i.e. you don't have to explicitly call a destructor). Without exceptions or panics, you can call a destructor. With them, you'd have to catch, call a destructor, and then rethrow. Gets hairy with a lot of resources. RAII solves this, but otherwise it's doing minimal work.

This isn't true at all. RAII is mostly just about acquiring resources (doing any necessary tasks), then executing a block depending on them, then freeing them (doing any necessary tasks)

>Well, yes, if you encode a linear type theory in a metatheory then you get linear types. Monads have fuck all to do with that, though.
No, I'm literally saying create an ST-style monad and require that the number of times it's referenced is 1

Purity is an unrealistic ideal that has little to do with reality. Why do you think nobody uses Haskell? All functions are sluts.

>RAII is mostly just about acquiring resources (doing any necessary tasks), then executing a block depending on them, then freeing them (doing any necessary tasks)
Create resource A
Use resource A
Use resource A again
Destroy resource A
That's not RAII. Don't dilute things.

>No, I'm literally saying create an ST-style monad and require that the number of times it's referenced is 1
Sounds like a lot of work when you could just have linear types.

data Console' r = Ask (String -> r) | Say String r

or
template
struct Console' {
enum { isAsk, isSay } state;
union {
function ask;
tuple say;
}
}


admittedly using the free monad can make the patterns more awkward (you need to use f (Free (...)) but I didn't want to explicitly show writing functor/applicative/monad instances

>That's not RAII
That's RAII

So RAII just means using resources correctly? RAII is common sense?

>are men who live in reality are cucks
Going back to my anime girls and pure functions ;_;

Yeah. It's one of those things academics gave a weird name to so they could inflate their own self-importance and pretend to be part of the industry.

>simplicity of java

Recommend me some Java programming books please.
I've made simple 2d games, but I'm still a novice.

Laptop is dead, got to wait 2 weeks for my desktop parts to arrive.
Need to satisfy my programming urges somehow.

>Sounds like a lot of work to add linear types when you could just have linear types.
Sounds like a lot of work to have linear types when you could just not.


A bunch of these terms get made up and thrown around.
The idea of RAII is that it's automatically done for you, in C++ by the constructor and destructor.

In RAII, holding a resource is a class invariant, and is tied to object lifetime: resource allocation (acquisition) is done during object creation (specifically initialization), by the constructor, while resource deallocation (release) is done during object destruction (specifically finalization), by the destructor. Thus the resource is guaranteed to be held between when initialization finishes and finalization starts (holding the resources is a class invariant), and to be held only when the object is alive. Thus if there are no object leaks, there are no resource leaks.

(Wikipedia)

tl;dnr you just make a class for the resource with a constructor allocating/initialising and a destructor freeing

>Academics
What the fuck am I reading?
This really pisses me off.
It was created by C++ engineers.
That's why it's called "Resource Acquisition Is Initialisation" and is primarily known through constructors and destructors.

Stop blaming everything on the academic boogeyman.

RAII doesn't specifically mean creating resources in a constructor and destroying them in a destructor so that allocating the object on the stack means automatic destruction even if an exception is thrown?

Because I'm pretty sure that's what the term means.

The Scheme Programming Language by Kent Dybvig

>usefulness of haskell

I can't understand your post over all the academic jargon you're using.

what text editor is this?

>Sounds like a lot of work to have linear types when you could just not.
Linear types are rather easy to add to a type theory.

Now, where monads (monadic regions) become useful even if you have linear types is with borrowing, since lifetimes do form a stack.

Effective Go

vim

Editor: Atom
Font: Fira Code
Theme: One Dark

I know nothing beyond about half of Calc 2 (I've done the Mathematics A-level).

Can someone please explain monads to me, or give me a resource to learn about them, or if necessary point me to where I might learn about the required mathematics before I start with monads?

First for Fuuzetsu.

A monoid in the category of endofunctors, duh!

Linear types cannot provide the benefits of monads

A monad is a generic type that provides "structured value", a function to make a pure function work on a "structured value", a function to turn a regular value into a "structured value", and a function to turn a "doubly-structured value" into a "singly-structured value"

from what we can see, you also didn't learn how to use google

There are no required mathematics unless you want to personally derive the type class from "monoid in the category of endofunctors".

Linear types are better than monads at making computations pure. That was the point from the very beginning.

Probably because literally all the resources are shitty.

Thanks. What's a "structured value"?

It depends on the monad, it's one of the defining features of it.
Note a "structured value" could be anything from a plain value ("no extra structure" being its own kind of structure), to a list of values, to an IO computation that produces a value and performs IO side effects.


For instance, say that you're working with the list monad

Your "structured values" are lists.
The generic type is "list" (you can have a list of any type, it is generic)

Making a pure function work on a list is just mapping the function on the list - i.e. applying the function to each element of the list. (e.g. add 2 to each element of an array)

Turning a regular value into a structured value (for lists) is just returning a single element list. (One consisting just of that element.)

The double-structure to single-structure is just concatenating the list of lists.


>Linear types are better than monads at making computations pure. That was the point from the very beginning.
No it wasn't, someone said "use linear types instead of monads".
There are lots of benefits of monads.

>No it wasn't, someone said "use linear types instead of monads".
Where?

...

And there is another way to define a monad, where rather than a join/flatten operation (double structure to structure) you have a "bind" operation. You can define join in terms of bind and vice versa.

Bind takes a function from a regular value to a structured value, and turns it into a function from a structured value to another structured value

ah. well, in that case, I kinda agree with you.

All I know is we were talking about monads and somebody was like "you should use linear types instead".
But anyway, my point is linear types don't "replace" monads.

Very informative, I understand the list example.

But why couldn't a similar thing be accomplished with a class and methods in another language like C++?

>All I know is we were talking about monads and somebody was like "you should use linear types instead".
Where?

>But anyway, my point is linear types don't "replace" monads.
They don't replace them entirely, they replace them for resource safety.

You can, but it will be ugly.

I don't understand what you're talking about, but it sounds pretty complicated so I'm certain it's bullshit.