Differences are the usual differences between type
and newtype
.
A type
A synonym is simply a new name for an existing type. type
synonyms cannot be partially applied because the compiler extends the definition during type checking. For example, this is not good, even with TypeSynonymInstances
:
type TypeCont ra = (a -> r) -> r instance Monad (TypeCont r) where -- "The type synonym 'TypeCont' should have 2 arguments, but has been given 1" return x = ($ x) k >>= f = \q -> k (\x -> (fx) q)
newtype
s, while operatively equivalent to their types, are separate objects in the type system. This means that newtype
can be partially applied.
newtype NewtypeCont ra = Cont { runCont :: (a -> r) -> r } instance Monad (NewtypeCont r) where return x = Cont ($ x) Cont k >>= f = Cont $ \q -> k (\x -> runCont (fx) q)
source share