Hi all In this url http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html... one can read about "Type synonyms in the instance head". A quote: "You cannot, for example, write: type P a = [[a]] instance Monad P where ... This design decision is independent of all the others, and easily reversed, but it makes sense to me." It does not make sense to me! Could anybody explain why this makes sense? Below, I will try to explain why it does not make sense to me. If I have: data LongAndUglyName a = ... type ShortAndTellingName a = LongAndUglyName a It seems to make sensible to: instance Foo ShortAndTellingName Also it is called a type _synonym_ and the type synonym and what it is synonym for, should therefore be interchangeable. This restriction do not only apply to instance heads, but also to contexts, as in: instance (Foo LongAndUgleName) => class something ... Here again LongAndUglyName cannot be replaced by ShortAndTellingName. This can be annoying if you have a lot of these instance declarations. Also what the type synonym is synonym for, may not have any name and thus properly not be telling at all, as in: type TellingName a = \a -> String /Mads Lindstrøm
Mads Lindstrøm wrote:
"You cannot, for example, write:
type P a = [[a]] instance Monad P where ...
This design decision is independent of all the others, and easily reversed, but it makes sense to me."
It's not clear to me how this can be reversed. Wouldn't reversing this mean introducing "type lambda", and doesn't that raise all kinds of nasty issues (like having to type-annotate function applications)?
If I have:
data LongAndUglyName a = ... type ShortAndTellingName a = LongAndUglyName a
It seems to make sensible to:
instance Foo ShortAndTellingName
You can do this instead: type ShortAndTellingName = LongAndUglyName -- Ashley Yakeley
Hello Mads, Thursday, February 02, 2006, 11:48:27 PM, you wrote: ML> instance (Foo LongAndUgleName) => class something ... ML> Here again LongAndUglyName cannot be replaced by ShortAndTellingName. ML> This can be annoying if you have a lot of these instance declarations. are you enabled "-fglasgow-exts" ? -- Best regards, Bulat mailto:bulatz@HotPOP.com
participants (4)
-
Ashley Yakeley -
Bulat Ziganshin -
Mads Lindstrøm -
Wolfgang Jeltsch