ML languages general

ML languages general.

Come talk about Haskell, Purescript, Ocaml, Reasonml, Elm, Idris, or Agda

Learn som gosh darned monads!

Attached: PureScript_Logo.png (220x220, 7K)

Other urls found in this thread:

stackoverflow.com/questions/20795747/haskells-is-a-magic-operator
blog.merovius.de/2018/01/08/monads-are-just-monoids.html
adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
twitter.com/NSFWRedditGif

Posting in this thread is an impure mutation. kys

Good thing those languages allow for impure mutations, it's just not the default behaviour

The ivory tower has a lot of nice things inside. The problem is that sometimes people get enticed by things that are pretty but impractical.

Monads are nice from a theory perspective, but are overkill complexity-wise for use in programming.

Dependent types are a huge waste of time. Just because something is proven to be "universal" doesn't mean it's the simplest solution for the majority of cases people care about. Providing lattice analysis -based compile-time assertions would be much more useful without needing anywhere near as much complexity. Further analysis could be added from there.

More abstraction doesn't mean better code. It just makes it harder to reason about what's actually happening.

Lazy evaluation is stupid; it's supposed to be an "optimization", but winds up wasting vastly more resources in overhead than it makes back in gains.

Linked lists are awful from a performance perspective. They're one of the least cache-friendly data structures out there. Thanks to the memory wall and the fact that the speed of light is finite, code that isn't cache friendly completely negates nearly all hardware improvements since the 80s. Anyone who claims any of this can ever be efficient needs to jump out of the top floor of the ivory tower.

Higher order functions are nice, but they need to be well-optimized to work well. They do heavily simplify control-flow analysis though, which is a really good thing.

but muh paredit

My favorite ML language is Rust

Python

I was the only one who chose haskell for my compilers class last semester
Holy shit that language is fucking amazing once you understand it.
Absolute delight to use.
Totally fucking useless, but an absolute utter delight.

I found out about PureScript the other day, I hope it catches on. So many jstards do this horrifying mess of functional nested scope programming and it'd be great if they'd just do it purely functional instead, at least then it wouldn't have ten trillion bugs

good points

why can't the compiler just allocate linked list nodes in a small local pools?

>wah wah functional programming is inherently slow because I only know rote memorized arguments against haskell

There's a lot of stuff like that that compilers could do. I'd love to see compilers start allocating things into memory arenas for extremely fast alloc/free.

No one does that outside of a few obscure research languages though.


I've been programming in C for 8 years and Haskell for 3 years. I've also studied hardware extensively, and know quite a bit about making efficient code.

Haskell has a lot of nice things about it, but it can also be a real pain sometimes, and its poor performance gets on my nerves a lot.

Nobody is seriously using linked lists for nontrivial collections in haskell. That's what vectors or other data structures are for.

Dependant types give you greater flexibility within a strong static type system, so you can do things that would otherwise not be possible in a strong static type system, Such as a strongly typed printf.

And I'd still take the few abstractions in haskell over any OOP garbage

Purescript is fantastic, solves almost every problem with JS, doesn't solve web platform stuff though.

Needs a good prelude replacement to restrict the number of imports

Totally agree on the OOP part.

There are simpler ways of solving those problems than dependent types.

Linked lists are the default. The default tool is the most important to get right.

The type of printf is literally dependant on the value of its arguments. It's the definition of dependant types if you care about type safety.

The weaker solution is 'don't use printf'

Meh, daily driving Haskell I don't really feel like it's a big deal to swap out a linked list for a vector, etc. I can make my own constructors so any structure can feel first class.


Also if laziness is a problem you just use a strict data type for your problem, or just use the language extension for strict data, effect Ely removing laziness. Nbd.

not until it's realized.

monads aren't complex, they are just badly marketed and taught.

So much this.


Also you can just write Elm or ocaml and not concern yourself with monads

I've studied the category theory myself. Compared to the alternative, monads are much more complex.

Simple alternative; just have an IO tag that is required for functions that do IO, and have IO operations in functions happen sequentially unless otherwise stated.

Simple, intuitive, monad-free, solves all the same practical problems.

If you really care about the Kleisli categorical interpretation of your types, fine. Use monads then. If you want simple IO and side effects, there are simpler ways it could be done.

kek

i think your idea is nice, but then you have all the plebs using your io tag all the time and you end up with the usual pajeet tier java code. i suppose you never get around this. the IO barrier I guess is a filter. I wonder how they go with this at facebook ..

That doesn't happen for the same reason even pajeet java code doesn't go around annotating every method with throws Exception.

It's awkward. That deters you from using it all the time.

Custom operators in Haskell were a mistake.

I agree, you should only be able to define prefix functions and $ should be syntax (it already receives special treatment from the compiler)

Fuck of idiot, delete your garbage thread and learn what a "General" is.

>it already receives special treatment from the compiler
how? I thought it was just defined with a different fixivity.

Something to do with impredicative types.

>impredicative types.
sorry, i'm kindof a brainlet?

It's like rank N types, but it works inside all type constructors instead of just the (->) type constructor. So you can do
[forall a. a]
I don't really understand how this relates to ($) either but apparently there's some compiler magic to make it work.

sorry to keep bothering you, do you have any links that explaing this? Searching for haskell ($) operator on google doesn't really work well.

stackoverflow.com/questions/20795747/haskells-is-a-magic-operator

Is it worth it to learn Elixir or just directly learn Erlang?

thanks fren

I'd say elixir is for ruby brainlets and neuters the flexibility of Erlang.

I agree monada are easy.

but category theory fags need to fuck off.

>and have IO operations in functions happen sequentially unless otherwise stated.
how do you do this without statements?

all bullshit

This was much needed

yeah, category theory isn't actually all that useful for day-to-day haskell programming.

I'm thinking if we do another ML Language general it should be a rule up front that nobody cares about your arguments that C is superior.

something like: ITT: C has already lost the argument.

that's why they use throws RuntimeException

monads are not strictly from ML

Indeed effects are going to replace monads for stuff like the IO monad, aka why monads were needed

>been coding for 2 years
>i still have absolutely no idea what a monad is despite occasionally looking it up
>my brain just rejects it and deletes the memory
help me anons i dont want to be a pajeet shitter forever

can I get a quick rundown on how effects work?

do you know what a continuation is? because it's just that but generalised

*sigh*. you don't need to know what it is. just code. learn by example. and never write a monad tutorial even if you think it has clicked.

nope. please stop now.

>I've been programming in C for 8 years and Haskell for 3 years
congrats, you're a 21-year-old kid with a BS who thinks he knows everything

monads aren't specifically from M, but haskell and it's contemporaries use them much more explicitly than other languages

ok, to be a monad, first you have to be a functor, which means you have a map method,

so you have a data structure that holds a value `a` and you can take a function from `a -> b` and then you can transform the `a` in your data structure to a `b` that gives you the map method and BAM you have yourself a functor

then you need applicative functor, specifically 'pure' AKA return. which just means you can take an arbitratrary value and put it in your structure. so `a -> f a` takes an a and puts it in your functor.

monad is an applicative functor that has a join method. join says when you nest the structure inside itself, you have a way to flatten so `m (m a) -> m a`

monad has a really handy thing called bind, or in JS they call it chain, which takes a function that would return a nested monad when you map it, and then it joins the result, you'll also see this as =

you forgot about

so strictly speaking, you can derive with fmap and pure, you don't really need it other than a quirk of how haskell makes you implement it, because people use it as a way to provide monad-like behaviours to things that are not lawful monads

but for completenesses sake there's a method you can call `ap` or `apply` when you make an applicative functor, which can take a function out of one functor, and map it over another functor.

generally, this solves a problem of getting a curried function partially applied and stuck inside a structure.

so you have a function that takes two arguments, you map it over a maybe, and now you have a maybe function, or `ap` lets you apply the maybe function to a maybe value to get a maybe result.

oh I didn't know that actually, can you show me in terms of pure and ?

sure

data Box a = Box a
deriving (Eq, Ord, Show, Functor)

instance Applicative Box where
pure = Box

--- fantasy default implementation of where it's not a required part of the minimal implementation of applicative
() (Box f) ba = f a

or
() (Box f) (Box a) = pure $ f a

(these two implementations are equivalent)
pretty sure this is what the compiler will do in most cases when you derive applicative (with relevant pragmas enabled)

in some circles, there's an algebra called a pointed functor, which is just the pure method, seperate from

for reference, see Professor Frisby's Barely Adequate Guide to Functional programming in JS

I don't see how this can be generalized over all functors

>'don't use printf
Because it's slow as fuck, yes.

Does anyone use OCaml aside from Jame Street?
F#, OCaml or Haskell, why or why not each of them? What one has the best libraries and ressources? Also which ones work well on Linux?

wut, haskell does use an arena for the nursery (0th generation)

parametric polymorphism kind of makes it work for just about anything.

there might be a small variation for functors that wrap a function (Reader) but then you just use runReader to get the f and a out instead of pattern matching, then do the same damned thing.

idk, but I have heard that F# is not good with linux and doesn't have native compilation

This. If your purpose is to focus on data and models and results, there's no point to sperg with some weird language, it's a waste of time.

I'm a Proud OCaml developer.

Facebook uses ReasonML pretty extensively, it runs a lot of Messenger.com

i know companies using fullstack reasonML

technically ocaml

Seems like a stupid reinvention of the same thing.

People get spooked by monads, but it's literally the most barebones interface for side effects imaginable. Reformulating the monad definition, it says that: a) effectful actions are sequential and later actions may depend on return values of earlier ones b) there is an effect-free action which returns any pure value.

99 percent of single-threaded imperative brainlet code in the wild is monadic, all code is implicitly in the general effect monad.

If you try to drop parts of the requirements, almost certainly you end up implementing dumb crap. At best, by dropping dependency on return values, we get applicative functors.

This.
I find the understanding of monads to be generalisations of continuations to be an incredibly useful one for grokking the idea of them being used to control effects because it's patently obvious how continuations can be used to sequence actions.

Machine learning is a meme. Just use python, I guess.

Uni course wants me to learn Scala as part of the programming module, and I've only really had experience with Haskell (and Rust iterators, since those are pretty much all fp-style).
How fucked am I?

Attached: scala-logo.png (304x492, 78K)

>scala
No, thank you Pajeet.

Heyo /mlg/, question. What language has the most promising future for a simple syntax that sticks close to SML style? OCaml? F#? Maybe ReasonML as an even simpler version?

I want haskell job T.T currently trying to start PhD. but if that does not work then I wanna earn my programming money by using a language that brings me joy

By effects are you talking about linear types? I'm out of the loop here

Tfw F# is not in the OP list

Ive been using F# for some side projects now and gosh darn is it comfy af.

F# runs well on my Ubuntu box with dotnet core
I just run fsharpc file.fsx and run my files.

Youll eventually need more than one file, then the dotnet tool becomes useful.

I want to get into functional programming because OOP languages are getting a bit boring for me. So where should I start and which languages are best for this? I have intermediate experience with C++ and Python

Go with Haskell if you wanna try something completely foreign-looking compared to other languages, I found it quite the fun mental exercise when I first started using it.

I see , also is OCaml is any good?

I think ocaml and/or reason Is pretty good.

Basically you get a lot of the type benefits and functional stuff as Haskell. But you don't have to fight to do some effects, also if you need to do OO, Ocaml has all the tools to do so.

Plus you get web and native compilation targets / interop.

FFS, how many effects are there when using a List?

that's not their only use though, and this is a poor definition of a monad. this is why people should just code and stop talking about monads.

blog.merovius.de/2018/01/08/monads-are-just-monoids.html
adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html

The first link is more theoretical, the second is supposed to be more "practical", though I don't know if it's actually as good as the person who recommended it thought it was.

Also read "Monads for Functional Programming" by Philip Wadler.

To try to put it in my own words, a monad (in Haskell terms) is a data type parameterized by a single type (for example, List) together with two functions with certain type signatures (look it up), satisfying certain conditions on how they compose (look up monad laws). That's it - it's a data type and two functions. Any data type of a single type parameter, together with two functions satisfying the types and constraints I mentioned, constitutes a monad.

but muh burritos

plenty of effects with list, they just happen to be the kind of effect that we're used to thinking of as pure. in a list, we're manipulating control flow through iteration.

a list is also non-determinism.

no. please stop posting this garbage.

the adit.io post isn't too bad. but i am not going to even read one with a title "monads are just monoids". no. no. no. that's just not right.

>i dont understand it therefore its garbage

brainlet

>that's just not right
As far as category theory goes, it is. But it's true that you don't need to understand the categorical concept to use the identically-named-yet-distinct programming language concept (I certainly wouldn't claim to have a good understanding of category theory monads). It's also true that people generalize from examples better than understanding abstractions directly, which is what names Wadler's paper such a good introduction.

names -> makes

t. phoneposter

I'm doing a school assignment to learn haskell but i get this error: *** Exception: Prelude.chr: bad argument: (-3). Does anybody here know how to solve this? The assignment is about generating images with various shapes and colors in the ppm format using haskell.

This only happens in the very last example which was already fully defined to generate a fairly complex image utilizing the code I wrote myself. The image I want is written to disk, but only the first half of it is what I expected with the rest being black. Which implies that it crashes halfway through.

Think about it this way, I'm assuming you know that you can apply a function to something inside of some context (i.e. and array) using the map function. What happens if the function you're applying returns another value inside of a context? You'd end up putting those values inside of another context. To avoid this, after mapping the function you flatten (or join) it into one context again. This is why bind is sometime called flatmap in other languages.

So, for example lets say there's two extremely trivial functions.
f :: Int -> Maybe Int
f a = Just (a + 1)
g :: Int -> Maybe Int
g a = Just (a + 2)

If I called f 1 I'd get back a value of (Just 2). I then want to apply the g function to the 2 inside of that value I could use fmap. But that doesn't exactly do what you want because fmap (g) (f 1) returns (Just (Just 4)). So for these types of functions we want to collapse the two contexts into one. That's exactly what join or flatten does so then we can do join $ fmap g (f 1) = Just 4. This is exactly what the bind operator in Haskell does: f 1 >>= g = Just 4.

The Monad Laws are just complex ways of saying that the functions can be composed and there is a function (pure or return) that does nothing and has no side effects.

Attached: 1560214070329.png (1920x1600, 754K)

sounds like a stack overflow question, kid,

but when I've seen like this it's because you're using ghc-mod with the wrong compiler version or something.

whats your build system? run it in stack or just recompile your dependencies.

if you're going to post an error looking for help, maybe link your repo and show the full, verbose error you're getting. including the line number it occurs on.