[Haskell-cafe] How to spot Monads, Applicatives ...

Joe Quinn headprogrammingczar at gmail.com
Sat Jun 18 02:14:32 UTC 2016


On 6/17/2016 6:16 PM, Tom Ellis wrote:
> On Fri, Jun 17, 2016 at 05:44:55PM -0400, Joe Quinn wrote:
>>>> newtype MyState a s = Mk {unMk :: s -> (s, a)}
>>> I can't write Functor, Applicative, Monad instances for it. Can you?
>> A Functor instance is pretty easy, but Applicative is off the table
>> without constraints on what a can be.
>>
>> instance Functor (MyState a) where
>>    fmap (Mk f) g = Mk (\s -> let (s', a') = f s in (g s', a'))
> I suggest you try compiling it :)

Doh, you're right. s is in both positive and negative positions there.



More information about the Haskell-Cafe mailing list