4 ms·
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
by b0afc375b5 4y ago
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