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

martin martin.drautzburg at web.de
Sat Jun 18 08:31:54 UTC 2016

Am 06/17/2016 um 11:44 PM schrieb Joe Quinn:

>>>> On 2016-06-15 11:54 AM, martin wrote:
>>>>> why is the state "s" in the state monad the fixed
>>>>> type and the "a" the type parameter? When I am writing state code without the State monad the two look like equal
>>>>> candidates. Why not have "State a" monad, which threads an a-typed value and spits out states?
>>>> You mean like this?
>>>> newtype MyState a s = Mk {unMk :: a -> (s, a)}
>>> No, I meant
>>> newtype MyState a s = Mk {unMk :: s -> (s, a)}
>> I can't write Functor, Applicative, Monad instances for it. Can you?

No I can't. But what is the correct train of thought here?

Suppose I came to the conclusion that "s->(s,a)" is useful to model stateful computations. Next I want want to make it a
Functor. This raises two questions:

(1) Why do I want to do this in the first place?

(2) What keeps me from trying "instance Functor (MyState a)" instead of "instance Functor (MyState s)? Is trying it the
wrong way and failing the only way to make that choice? I suppose there must be some reasoning which is closer to the

More information about the Haskell-Cafe mailing list