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

Joe Quinn headprogrammingczar at gmail.com
Fri Jun 17 21:44:55 UTC 2016

On 6/17/2016 5:02 PM, Albert Y. C. Lai wrote:
> On 2016-06-17 03:04 PM, martin wrote:
>> Am 06/15/2016 um 07:10 PM schrieb Albert Y. C. Lai:
>>> On 2016-06-15 11:54 AM, martin wrote:
>>>> Paticularly I am having difficulties with the *->* instances. E.g. 
>>>> 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)}
> This seems to thread s and spit out a, the opposite of what you said. 
> So much for natural language "intuitive" "conceptual" "meaningful" 
> descriptions.
> I can't write Functor, Applicative, Monad instances for it. Can you?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

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'))

More information about the Haskell-Cafe mailing list