top | item 45325029

(no title)

Asraelite | 5 months ago

https://tech.nextroll.com/blog/dev/2022/11/11/exploring-mona...

The thing that always makes FP concepts click for me is seeing them explained in a language that isn't Haskell or similar.

I don't know why people are so obsessed with using Haskell for tutorials. Its syntax is a nightmare for newcomers and you can do FP in so many other languages.

discuss

order

mrkeen|5 months ago

For instance, C#:

  public static System.Collections.Generic.IEnumerable<TResult> SelectMany<TSource,TCollection,TResult>(this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,System.Collections.Generic.IEnumerable<TCollection>> collectionSelector, Func<TSource,TCollection,TResult> resultSelector);
compared to:

  (>>=) :: m a -> (a -> m b) -> m b
Guess which one I googled, and which one I typed from memory.

mrsmrtss|5 months ago

In your c# sample full namespaces are unnecessary and will add only noise in this context.

bazoom42|5 months ago

Haskell have some syntactic sugar which makes monads nice to use, which is why monads are popular in Haskell.

Explaining monads in JavaScript or C# might show the mechanics but will not show why anyone would actually want to use them, since it just result in overly convoluted code.

Asraelite|5 months ago

I strongly disagree. Monads are used all the time in non-FP languages. Parser combinators are one common example. It's just a programming pattern which gives the benefits of global variables without the downsides. They work perfectly fine without dedicated syntax.

I was very confused about what they were until I saw an article similar to the one I linked, and then I realized that I had actually been using monads all along, I just didn't know they were called that. I think a lot of developers are in the same boat.