4 ms·
Neat. I did see that liftM3 takes a function of 3 arguments, and just plain ignored that fact in my example :) And to be clear, for <$> and <*>, you need a Fun
by ch 17y ago
Neat. I did see that liftM3 takes a function of 3 arguments, and just plain ignored that fact in my example :)
And to be clear, for <$> and <*>, you need a Functor instance defined for you type right?
Are there benefits to using one or the other, they seem to evaluate the same, is GHC able to optimize Monad and Functor equally?
- jmillikin 17y agoRight -- liftM and friends are for monads, <$> and <∗> are for functors. All monads are supposed to be functors, though there's currently no type-level guarantee for historical reasons. Most instances of Monad also provide an instance of Functor. Are there benefits to using one or the other, they seem to evaluate the same, is GHC able to optimize Monad and Functor equally? I believe there's currently no special optimizations for either case, though as I don't poke around in GHC this statement may be mistaken. The primary advantage of the application operators over liftM is that there's no liftM6, liftM7, etc; you can type <∗> as much as you want.
- jrockway 17y agoIn Haskell, <∗> is implemented in "Applicative", not "Functor". So a Functor instance is not enough. <$> is from Functor, however.
- jmillikin 17y agoOh, that's right -- I forgot applicatives are a separate class. Regardless, the concept of "lifting" pure functions is separate from monads, which exist to enforce sequencing.