While I know that there is a TypeSynonymInstances extension in GHC, I have no idea how “dangerous” it is and I wonder if this restriction is arbitrary, kind of like the Monomorphism Restriction, or if there are deeper reasons for it.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
TypeSynonymInstancesis perfectly safe. Since anything potentially fancy like partially applied type synonyms is disallowed, it has exactly the same effect as typing out the the right hand side of the type synonym in the instance head, i.e.is the same as
However, note that both instances require
FlexibleInstancessince they contain nested type constructors as well as repeated type variables. In general, this will often be the case after expanding type synonyms.I think may be the reason why they’re disallowed by default.
However,
FlexibleInstancesis also a perfectly safe extension. The worst it can do is cause a compile-time error if you try to define overlapping instances such asAs for why
FlexibleInstancesis not available by default, I can only guess that it’s to simplify the language. The standard rules for instance heads ensures that the only way instance definitions can overlap is if the type constructors in the instance heads are identical, while withFlexibleInstanceschecking for overlaps is slightly more difficult.