[Haskell-beginners] Code golf
Silent Leaf
silent.leaf0 at gmail.com
Fri May 20 02:50:28 UTC 2016
The interesting bit is, the following function
> \φ ma mb -> join (pure φ <*> ma <*> mb)
which i like to write as follows using ((&) = flip ($)) [infixl 1]
> \φ ma mb -> pure φ <*> ma <*> mb & join
(but it's just personal taste) is very similar to (=<<), aka (flip (>>=))
except the first argument (here φ) has type (a -> b -> m c) instead of (a
-> m b), and of course the lambda above takes an added argument too (mb).
Some could call it "bind2" (even if it's the flipped version of (>>=) that
is being generalized), and well, some do. For those interested, there are
several options are available to import it (along possibly with some of its
siblings), from several libraries. (List possibly non exhaustive.)
http://hackage.haskell.org/package/prelude-generalize-0.4/docs/Prelude-Generalize.html#v:bind2
http://hackage.haskell.org/package/SimpleH-1.2/docs/Algebra-Monad.html#v:bind2
http://hackage.haskell.org/package/definitive-base-2.3/docs/Algebra-Monad-Base.html#v:bind2
your problem become btw then:
> doIt = bind2 update a b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160520/d8315a31/attachment.html>
More information about the Beginners
mailing list