News for hackers. Stuff that matters.
Re:The Haskell job market has been growing steaily since 2008 by anta40 on Sunday July 16, 2023 @03:11AM (#36744385)
What kind of applications your team are working it? How's the overall development process felt? I'd like to know the reason to choose Haskell over other languages.
Re:The Haskell job market has been growing steaily since 2008 by ilikebits on Sunday July 16, 2023 @03:32AM (#36744492)
Re: applications and language comparison, see my answer over at https://news.ycombinator.com/item?id=36744384

Re: development process - it's very similar to development in other languages. Write, compile, yell at compiler, push, complain about how slow CI is, deploy. You know, the usual.

I think the most interesting difference is the _onboarding_ curve. Haskell's curve is pretty brutal, although I think most of this is because of bad pedagogy (many monad tutorials are bad, and beginners can't tell) rather than because of intrinsically difficult concepts. Some observations:

1. Empirically, zero to code review is roughly six weeks for a professional industry software engineer. It's not that much longer than other languages we've had to teach. But it _feels_ very brutal because zero to side project is roughly three or four weeks. Contrast this against Go, where zero to side project is about five minutes.

2. Having an experienced Haskell engineer on your team to start with makes a WORLD of a difference. You've gotten a type error - why? Is it because GHC is doing weird backwards type inference stuff again? Or is it because you've misunderstood this fundamental concept? Or is it because you've done a typo, and GHC has inferred a downstream site to be a type error? This sort of thing is very difficult to explain in words and in general, and much easier to pick up through experience and mentorship. If you do not have an experienced Haskeller at your disposal, I would strongly recommend starting with side projects first, and using the Functional Programming Slack (fpslack.com), who are some of the friendliest and most patient folks I've had the pleasure of talking to.

Re:The Haskell job market has been growing steaily since 2008 by Tade0 on Sunday July 16, 2023 @04:56AM (#36744918)
> (many monad tutorials are bad, and beginners can't tell)

It appears monads truly are something you can either understand or explain, but not both.

I find it suspicious. I mean, plenty of Haskell devs out there, surely it's not that hard?

Re:The Haskell job market has been growing steaily since 2008 by icrbow on Sunday July 16, 2023 @05:38AM (#36745135)
It's like explaining a hand with four fingers and a thumb. The whole story is... ugh. But you can grasp enough of it to start using almost right away.
Re:The Haskell job market has been growing steaily since 2008 by PartiallyTyped on Sunday July 16, 2023 @05:58AM (#36745220)
You can just say that a monad is a way to chain operations together by wrapping a value. The consumer usually doesn't need to know the gore-y details of how a monad is implemented, only the purpose of it and how to use it.

A Maybe monad just says the value may be Something(x) or Nothing. You won't know until you run the computation. If you use flatmap and give a function that takes an x and gives a Maybe[x], the monad will first map into Maybe[Maybe[x]] and then flatten into Maybe[x]. The computation has not happened until you execute it and internally all the functions have been composed together.

A List[A] just says, give me a function A->List[B], and I will flatmap (flatten `compose` map) it. So it maps each element into a possibly empty list of Bs, and then flattens it by concatenating them.

You can define your own monads, and as long as they obey the laws of monads, you get a bunch of stuff for free.

Re:The Haskell job market has been growing steaily since 2008 by icrbow on Sunday July 16, 2023 @09:10AM (#36746605)
You say "by wrapping a value" and then confuse it with the wrapper right away. No, monads are not wrappers. Some wrappers are monads, but not all. inb4, monads are not pipes either.
Re:The Haskell job market has been growing steaily since 2008 by PartiallyTyped on Sunday July 16, 2023 @09:53AM (#36747008)
Sure, a monad is a type constructor. The constructed type allows you to compose transformations.

Each monad constructs a type that behaves differently and expects different things, but in general; the monad is defined by a unit/point/return function which brings a value into the monadic context, and a flatMap function aka bind, which further breaks down to “flatten after map”.

So List[_] is a type constructor, given a type T, it produces a List[T], which defines some transformations. Return creates a single element list, and flatmap takes the A->[B] applies it everywhere and then concatenates.

The nice thing about the wrapper analogy is that even though it is technically wrong, it is easier for people to get it because it follows naturally from OOP and it is a sufficiently useful mental model imho.

Re:The Haskell job market has been growing steaily since 2008 by jghn on Sunday July 16, 2023 @10:19AM (#36747286)
IMO the spirit of this answer is a big part of the problem. This might not be exactly what the GP was saying but I've found you can quickly get a dev up to speed with a "good enough" sense of what a monad is. One that'd cover a vast majority of their needs, at least in the early going.

But then there are always people who start popping in and pointing out how those definitions aren't quite right. Which is true. But does it matter *for practical purposes* to give a dev a useful for now mental model that they can then use to figure the rest out later? I'd say no.

Re:The Haskell job market has been growing steaily since 2008 by PartiallyTyped on Sunday July 16, 2023 @10:41AM (#36747543)
The intention of the comment was just to give a good enough model so that devs can just get going :)
Re:The Haskell job market has been growing steaily since 2008 by jghn on Monday July 17, 2023 @09:18AM (#36757906)
Yes, sorry, I was agreeing with you & not the person who responded.
Re:The Haskell job market has been growing steaily since 2008 by bPspGiJT8Y on Sunday July 16, 2023 @12:25PM (#36748707)
Then why not just say that a monad (instance) is a type `t` which implements `bind :: t a -> (a -> t b) -> t b`? It's as down to earth and down to the point as it gets, and each time a new dev thinks out a code path which would lead to `t b` they'd remember `bind`. No need for containers metaphors at all.
Re:The Haskell job market has been growing steaily since 2008 by PartiallyTyped on Sunday July 16, 2023 @01:18PM (#36749349)
What’s a `type`? What is `t a`? How do I get `t a`? How does `t b` become `b` when I bind again? Where is `b` after I bind? What about the reader monad and the state monad? Those have different signatures, so what gives?
Re:The Haskell job market has been growing steaily since 2008 by icrbow on Monday July 17, 2023 @06:00AM (#36756072)
This. Just point to the definition in your language (NOT the category theory, unless that's what you're coding in).

In Haskell, a Monad is a type class with a method `bind`. In Scala that would be a `flatten` or whatever.

If a person who's asking doesn't yet know what the "type class" is, or how to read signatures, your "monad tutorial" would not make much sense anywat. Guide them to learn the prerequisites first.

Re:The Haskell job market has been growing steaily since 2008 by icrbow on Monday July 17, 2023 @06:17AM (#36756182)
For practical purposes you don't have to know what the monad "is". You need some good practical examples how to wield them.

Knowing some prehistory about doesn't affect usage. And metaphors are very tricky and personal.

The personal part is where the "monad tutorials" fall flat. They assume shared context which may or not may not be actually shared by a random reader on the internet. Yes, some monads are really about "wrapping a value" or whatever.

Reading a post using this metaphor when you want such a wrapping and/or deal with chaining wrappers regularly can bootstrap your understanding in no time. But if you're reading "wrapper"-flavored tutorial while dealing with "pipes" then the spell breaks, you end up confused, and another one joins the "monads are uncomprehensible" group.

Teaching is hard enough. Writing good tutorials is even harder. Successfully giving an universally good drive-by explanation is next to zero probability.

I suspect this is a knowledge variant of "XY problem" and you have to establish more context before answering.

And another problem that "what is a monad" is already a meme. Everyone has the burning desire to ask it, but usually there's no practical need for the answer. Without that confusion ensues. Or, even worse, a false understanding gets locked in and starts to proliferate, sustaining the memetic chain reaction.

Re:The Haskell job market has been growing steaily since 2008 by goto11 on Sunday July 16, 2023 @10:41AM (#36747532)
Monads are a pattern for function chaining.

Most tutorials go off the rails because they confuse types supporting this pattern with "being a monad". For example, arrays in JavaScript support the pattern through the `flatMap()` method, but saying "a JavaScript array is a monad" is misleading because most of what people do with arrays are unrelated to this.

Re:The Haskell job market has been growing steaily since 2008 by embwbam on Sunday July 16, 2023 @11:27AM (#36748081)
They’re like promises or futures, but limited to chaining only one type of thing:

Maybe (optionals) - chain steps and abort if any step is empty.

IO - perform IO side effects, and run the next step when this one completes. Just like a async/await.

You use monads all the time in other languages! Haskell just has many more kinds and allows the programmer to make their own.

I always twitch when I hear someone say you can’t both understand and teach them. Did I succeed?

Also note that you don’t have to totally understand monad machinery to use them productively, only to write your own.

Re:The Haskell job market has been growing steaily since 2008 by muxator on Sunday July 16, 2023 @11:55AM (#36748408)
Humble question:

> Maybe (optionals) - chain steps and abort if any step is empty.

Could this be (remotely) akin to the following shell pattern?

    set -o pipefail
    cmd1 | cmd2 | ...
This would either return the result of a successful execution of tje whole pipe, or return at the first command erroring out.

Does it make any sense?

Re:The Haskell job market has been growing steaily since 2008 by embwbam on Sunday July 16, 2023 @01:33PM (#36749526)
Yes that’s exactly what the Maybe monad does! It would look like this in Haskell code

    doStuff :: Maybe X
    doStuff = do
      r1 <- cmd1
      r2 <- cmd2 r1
      …
      return rX
Which is syntactic sugar for:

    doStuff = cmd1 >>= cmd2 >>= …
Re:The Haskell job market has been growing steaily since 2008 by dllthomas on Thursday July 20, 2023 @06:52PM (#36807852)
A sometimes important difference is that every process in the pipeline is spawned at the start, and may operate on partial input. A function returning Maybe needs to complete before we know whether it returns Just or Nothing, and we can't start the next function until we have the Just in hand, as that's the input to the function.
Re:The Haskell job market has been growing steaily since 2008 by goto11 on Sunday July 16, 2023 @12:57PM (#36749114)
> You use monads all the time in other languages!

No you don't. You are confusing monads with features which can be implemented using monads. In Haskell monads are used for modeling side effects, but this is not the case in other languages. In Haskell exceptions are implemented using monads, but this is not the case in other languages.

Re:The Haskell job market has been growing steaily since 2008 by embwbam on Sunday July 16, 2023 @01:35PM (#36749542)
I find promises and futures in other languages (python, JavaScript, rust) close enough to how monads work to gain a very productive working intuition for how they work.
Re:The Haskell job market has been growing steaily since 2008 by goto11 on Sunday July 16, 2023 @06:05PM (#36751878)
But how would you e.g. explain the monad laws from this intuition? Promises in JavaScript are not monads and does not obey the monad laws.
Re:The Haskell job market has been growing steaily since 2008 by embwbam on Monday July 17, 2023 @09:27AM (#36757991)
You don’t need to explain the monad laws to a beginner. They don’t need to know what bind does. All they need to know is how to use do syntax, and enough of how it works to use IO, Maybe, State, and a few others.

After they’ve been working for a month or so, they’ll “get” monads on a gut level, and the details won’t be so confusing to them.

Re:The Haskell job market has been growing steaily since 2008 by goto11 on Monday July 17, 2023 @11:45AM (#36759629)
Yeah, learning by example and by doing is the best way to learn any programming concept. But using misleading and confusing analogies along the way will just make the learning process harder, not easier.

Explaining monads in terms of promises and futures will make a beginner associate them with asynchronous programming, which might make some sense for some monads. But now show such a beginner a simple list comprehension and explain it is also a monad, and I assure you they will be very confused! Explaining concatMap in terms of promises is a very convoluted way to explain something quite simple.

Re:The Haskell job market has been growing steaily since 2008 by embwbam on Tuesday July 18, 2023 @10:44AM (#36773218)
I see what you’re saying. I agree that abstract metaphors confuse people. But clearly, the way we are teaching monads right now isn’t very effective for most people.

Haskell comes from a population that loves to understand things from the ground up, and most people learn by doing.

So, what if, instead of an abstract burrito metaphor, we taught people 4 monads: List, Maybe, State, and IO. We explain how do syntax does “something different” for each of them, and how IO is very similar to promises, but the others aren’t. Then we let them play with those for a few weeks, submit some PRs, let the panic of not understanding subside, and then teach them the theory?

Think about how JavaScript developers learn promises. They don’t understand how they work under the hood at all when they first start using them. Then, when they need to go deeper and look under the hood, that theory is connected to their practice, and makes much more sense to them.

Re:The Haskell job market has been growing steaily since 2008 by goto11 on Tuesday July 18, 2023 @04:09PM (#36778412)
> So, what if, instead of an abstract burrito metaphor, we taught people 4 monads: List, Maybe, State, and IO. We explain how do syntax does “something different” for each of them, and how IO is very similar to promises, but the others aren’t.

Yes, I am on board with that.

Re:The Haskell job market has been growing steaily since 2008 by consilient on Sunday July 16, 2023 @02:13PM (#36749944)
Yes you do. `flatMap`ping an array in javascript is using a monad every bit as much as `join`ing a linked list in Haskell. `Promise`s would be monads were it not for the (inexplicable, terrible) decision to make it impossible to nest them. C#'s `IEnumerable<_>` is not quite a monad, but only because it doesn't have a preferred implementation. Pick one, and it's as monadic as `Maybe` or `Either`. And of course function types are always monads.

What these languages don't have and Haskell does is a way to talk about all monads, all at once. Instead of

    replicateM :: forall m a . Monad m => Int -> m a -> m [a]
you have to separately implement

    replicateArray: <T>(count: number, ts: T[]) => T[][]
    replicateFunction: <S, T>(count: number, f: (s: S) => T) => (s: S) => T[]
    replicatePromise: <T>(count: number, t: Promise<T>) => Promise<T[]>
and so on.
Re:The Haskell job market has been growing steaily since 2008 by goto11 on Tuesday July 18, 2023 @11:52AM (#36774465)
Are you suggesting that flatMap is used all the time in JavaScript?
Re:The Haskell job market has been growing steaily since 2008 by tomsmeding on Sunday July 16, 2023 @12:29PM (#36748762)
Instead of rising to the bait and trying to explain monads, let's talk about why it seems to be hard to explain monads.

They're very general. Classes in OOP are general too — surely you can model lots of things with them — but a class always models a category of things with similar functionality, and an instance of that class is one of those things.

Monads are much more flexible than that. You can model nondeterminism with monads, as well as side-effects, exception-based error handling, state, (backtracking) search algorithms, and more. Could all of those things be an instance of the same OOP class? Surely not. Yet in Haskell, 'Monad' is just a "type class" (not dissimilar to an interface / abstract class in the OOP world).

Monad tutorials typically try to do one of the following things:

1. Try to explain the entirety of monads by giving a metaphor (burritos, anyone?) that only works for some of the instantiations of the pattern. It turns out to be hard to find a metaphor that covers all ground that Monad does, unsurprisingly. Personally I think this method is good, as long as you're honest about what it does not give you: an intuition for all Monad instances. It just gives you an intuition about some of them, but that could already be plenty to work with them usefully (and see 3. below).

2. Try to let the reader invent Monad by showing various instantiations and asking the reader to find the pattern. Personally I think this misses the point somewhat; yes, you can see the pattern, but that doesn't give any understanding per se. Why are those things similar, and why does it make sense to abstract over the idea?

3. Not actually explain, but instead say "work with them a bit and you'll understand soon enough". This is the one I'm most in favour of — after giving a special-purpose intuition for the monads you'll be working with as a beginner (IO, perhaps parser combinators, and not much else; perhaps lists (nondeterminism) to jump-start exploration into non-imperative monads).

Note that none of these give a nice and polished answer to what a monad is.

As alluded to above, the closest OOP equivalent to the kind of thing that Monad is, is a design pattern. It's a design pattern that can be encoded into a three-line definition in the language itself, and is super general.

Re:The Haskell job market has been growing steaily since 2008 by ilikebits on Sunday July 16, 2023 @05:02PM (#36751360)
Here's my take on a monad tutorial: https://lobste.rs/s/7cllte/monads_part_six_really_what_is_mo...

TL;DR: Monads are Promises and async/await, but generalized to different implementations of `.then`.

You are right to be suspicious; it is _not_ that hard! I think people just get confused and overwhelmed because (1) there are many separate different concepts that are all being introduced at once, and (2) you need to learn a new debugging methodology at the same time. I think the vast majority of this problem is the huge deluge of bad teaching materials (especially monad tutorials written by people who do not use Haskell in production) and the shortage of good teaching materials.

Re: 1 - some separate, orthogonal concepts that I have seen people mix up while trying to teach Haskell:

1. Effect tracking (which is a thing that we _do_ using monads, but is not intrinsically tied to monads - this would be better served by being taught as "dependency injection but stricter")

2. Non-eager evaluation (which is a language runtime evaluation choice that Haskell has made, and which motivates the usage of monads where most languages have function bodies, but is again not intrinsically tied to monads)

3. "Purity" (a more confusing way to explain 1)

4. "Mutable state" (another thing we represent with monads, but again is not intrinsic to monads)

5. Monads the math / category theory concept (don't bother with teaching this - it will not be helpful until you have intuition for writing and operating the programs themselves first, which takes at least a few months to build, and even then it is mostly useful as a source of advanced techniques for library writers rather than application writers)

At work, we've developed our own set of educational materials for teaching folks the language. I'm working on externalizing them in my spare time.

Re:The Haskell job market has been growing steaily since 2008 by shae on Sunday July 16, 2023 @09:28AM (#36746765)
We built an Android app in Haskell because Python was too hard for loading shared objects.

We shared from nothing in January, shipped the app last month.

We had 2.5 developers.

Re:The Haskell job market has been growing steaily since 2008 by penguin_booze on Sunday July 16, 2023 @10:54AM (#36747658)
> We built an Android app in Haskell because Python was too hard for loading shared objects.

Can you elaborate the process? The only reference I could only find this: https://wiki.haskell.org/Android.

How did you end up developing/deploying your UI?

Re:The Haskell job market has been growing steaily since 2008 by shae on Monday July 17, 2023 @09:19AM (#36757921)
We used reflex-frp, so our app was a webview that worked on localhost and Android. The docs say it also works on iOS but we don't have an iPhone.

The process was learning Functional Reactive Programming, then learning reflex-frp, then getting a contract with obsidian (creators of reflex) for one hour a week where we could ask questions.

( https://github.com/reflex-frp/reflex-platform )

We had a grant requirement to create a phone client for Tahoe-LAFS, a Python application with a bunch of dependencies, including ZFEC, a forward error correction library.

( https://tahoe-lafs.readthedocs.io/ )

( https://github.com/tahoe-lafs/zfec/ )

We needed bug for bug compatibility with the Python codebase, so I ran Tahoe on localhost and tested the Haskell client against the Python server. We used servant to build the API, since it builds both client and server side from the same description.

( https://hackage.haskell.org/package/servant )

Re:The Haskell job market has been growing steaily since 2008 by penguin_booze on Monday July 17, 2023 @12:50PM (#36760602)
Thanks for your notes. Any chance your app is on the Play store so that I can check it out?
Re:The Haskell job market has been growing steaily since 2008 by shae on Monday July 17, 2023 @01:16PM (#36761000)
I just checked, it hasn't been approved yet.

Should be named "private storage" when it does show up in the app store.

Even so, it won't be useful until you have a Tahoe-LAFS shared magic folder.

Hopefully we'll get funding to make a default shared folder for getting started!

Re:The Haskell job market has been growing steaily since 2008 by shae on Monday July 17, 2023 @01:06PM (#36760850)
I don't know if it's been approved yet, but it's open source: https://whetstone.private.storage/privatestorage/privatestor...
Re:The Haskell job market has been growing steaily since 2008 by shae on Thursday July 27, 2023 @12:28PM (#36896050)
Re:The Haskell job market has been growing steaily since 2008 by shae on Monday July 17, 2023 @09:39AM (#36758115)
From my personal viewpoint the most beneficial things we did:

1. mostly pair programming, so we all knew the current state of the codebase and the path forward

2. When we didn't understand something, we wrote a separate small prototype of that feature / library / reference to teach ourselves how it worked. ( async, monad transformers, lenses, many reflex features )

3. We paid Obsidian for a one hour a week meeting to help us when we couldn't figure it out by ourselves. ( https://obsidian.systems/ )

4. nix for cross compilation and build / dev automation

5. Several hours a week of explicit teaching each other what we knew. This might should go first in the list, as the culture of being open and teaching was a massive benefit. We had one hour a week where the nixpert taught nix, one hour a week where I taught beginning Haskell, another hour a week where I taught Advanced Haskell (things I was learning that might help). We also had two hours a week where we all got together and worked on the stickiest problem along the path to shipping.

Most software dev jobs I've had want me to "do the thing" and have zero time left over for teaching / training others. I wanted to take the opposite approach and this paid off far more than my already wild hopes.

Re:The Haskell job market has been growing steaily since 2008 by meejah on Monday July 17, 2023 @02:40PM (#36762233)
I would personally keep "pair programming" at the top of the list, this _really_ helps everyone learn.

Even more importantly, it tightens the loop between "write code, review code, change code, merge it finally" since you're basically doing all of that "at once" in the best case.

Re:The Haskell job market has been growing steaily since 2008 by AndrewKemendo on Sunday July 16, 2023 @11:04AM (#36747791)
That sounds amazing, can you discuss your dev/prod environments please? Link to product?

Thanks!

Re:The Haskell job market has been growing steaily since 2008 by shae on Monday July 17, 2023 @09:24AM (#36757971)
The whole thing is open source, pretty sure this is accessible without login:

https://whetstone.private.storage/privatestorage/privatestor...

Dev environment was our laptops, obsidian's "ob run" is friendly and helpful (but doesn't work well with haskell-language-server).

Dev environment was also our Android phones.

We used nix for cross compilation and build automation, lucky for me the other main dev is really good at nix.

Re:The Haskell job market has been growing steaily since 2008 by AndrewKemendo on Monday July 17, 2023 @03:13PM (#36762650)
Ah nix! Ok thank you very much
Re:The Haskell job market has been growing steaily since 2008 by pjmlp on Monday July 17, 2023 @04:58AM (#36755705)
Why not Kotlin then?
Re:The Haskell job market has been growing steaily since 2008 by shae on Monday July 17, 2023 @09:21AM (#36757943)
We don't know Kotlin. We both have some prior Java experience, but it's not our preference.

Since the original codebase is in Python, I would have used that if possible, but I spent eight weeks failing to load a shared object into a Python interpreter on Android. That got us to this past January.

I have had a Haskell job before, though I was entirely unfamiliar with Android dev.

In two days I was able to load a shared object into a Haskell interpreter on Android, so we tried that route.

Re:The Haskell job market has been growing steaily since 2008 by pjmlp on Monday July 17, 2023 @10:52AM (#36758985)
I see, given the pain of using the NDK, and having to make use of JNI for any meanigful Android API, that approach seemed quite strange, when only having to target Android, hence the question.