## FlexibleInstances

 1 2 3 4 5 6 7 8  -- Learning.hs data Vector a = Vector a a deriving (Show) class MyClass a where myFun :: a -> a instance MyClass (Vector a) where myFun = id

 1 2 3 4 5 6 7 8 9  ghci> :l Learning.hs [1 of 1] Compiling Main ( Test.hs, interpreted ) Ok, modules loaded: Main. ghci> myFun (Vector 1 2) Vector 1 2 ghci> myFun (Vector 1 2) :: Vector Int Vector 1 2 ghci> myFun (Vector 1 2) :: Vector Double Vector 1.0 2.0

 1 2 3 4 5  instance MyClass (Vector Int) where myFun = undefined instance MyClass (Vector Double) where myFun = undefined

  1 2 3 4 5 6 7 8 9 10 11  ghci> :r [1 of 1] Compiling Main ( Learning.hs, interpreted ) Learning.hs:10:10: Illegal instance declaration for ‘MyClass (Vector Int)’ (All instance types must be of the form (T a1 ... an) where a1 ... an are *distinct type variables*, and each type variable appears at most once in the instance head. Use FlexibleInstances if you want to disable this.) In the instance declaration for ‘MyClass (Vector Int)’ Failed, modules loaded: none.

## TypeSynonymInstances

 1 2 3 4  type VectorInt = Vector Int instance MyClass VectorInt where myFun = undefined