News for hackers. Stuff that matters.
Re:Haskell's Operator Glossary by b0afc375b5 on Monday September 19, 2022 @09:17AM (#32897890)
I'm not a Haskell programmer yet but from what I understand it's basically just function composition, with the condition that the functions return some kind of Functor.

In normal function composition, let's say you have function `tostr` that converts a boolean to string, and function `strlen` that computes the length of the string.

They have the ff. signatures:

tostr :: boolean -> string

strlen :: string -> number

If you compose these two functions, where you `tostr` then `strlen`, then the resulting function will have the ff. signature:

composed :: boolean -> number

Now let's suppose that `tostr` and `strlen` both return a Maybe monad, with the ff. signatures:

tostr :: boolean -> Maybe string

strlen :: string -> Maybe number

This is where the fish operator helps, because if we compose it normally it doesn't work because `strlen` expects a string, not a Maybe string. The fish operator will automatically unwrap the value, resulting in the ff. signature:

mcomposed :: boolean -> Maybe number

There are no comments on this comment yet.