[Haskell-cafe] Why can't we make an instance declaration on a type synonym?

jberryman brandon.m.simmons at gmail.com
Sat Jan 2 23:29:12 EST 2010


This may be a dumb question, but why can we not declare a Monad
instance of a type synonym? This question came to me while working
with the State monad recently and feeling that the requirement that we
wrap our functions in the State constructor is a bit... kludgy.

Why can't the State monad be defined this way?:

>    type State s a = \s -> (a , s)
>
>    instance Monad (State s) where
>        return a = \s -> (a, s)
>        m >>= k  = \s -> let
>            (a, s') = m s
>            in k a s'

It seems like Haskell's type system could understand the above, but
I'm interested in hearing the technical reason which I'm sure exists
for why we can't do this.

Thanks for any clues,
Brandon Simmons
http://coder.bsimmons.name/blog/


More information about the Haskell-Cafe mailing list