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

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Sun Jan 3 02:22:54 EST 2010


jberryman <brandon.m.simmons at gmail.com> writes:

> 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.
>

Because type defines an _alias_.  If you define "type Foo = Maybe Int",
then everywhere you have a "Foo" the compiler should be able to replace
it with "Maybe Int".

As such, if you have a custom instance on your type synonym (say a
custom Show instance for Foo), then which instance will the compiler
use?

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list