Reputation: 1543
Vec2 is working as data declaration, but i try to scrap my boilerplate with tuples in this scenario:
{-# LANGUAGE FlexibleInstances #-}
type Vec2 a = (a,a)
class Vector v where
foo :: v Integer
instance Vector Vec2 where
foo = (1,2)
Upvotes: 5
Views: 174
Reputation: 53871
Type synonyms can't be partially applied. Since they are essentially type level functions, deciding equality between partially applied type synonyms is akin to deciding extensional equivalence.
You're well within your power to do something like
{-# LANGUAGE FlexibleInstances #-}
instance Foo String where
...
Since String
is fully applied. There is a work around however, since types are curried, in some cases you can write things like
type Arr = ((->) Int)
And create instances for this since the type synonym is "fully applied".
In this case clever eta conversion isn't possible so you're going to have to use a newtype,
newtype SimplePair a = SimplePair {unSimplePair :: (a, a)}
Upvotes: 5