I've implemented a map type type family like this
type family MapT (t :: * -> *) (e::[*])
type instance MapT t '[] = '[]
type instance MapT t (a ': as) = (t a) ': (MapT t as)
It works with a type constructor :
type MList = MapT Maybe '[Int, String]
gives
'[Maybe Int, Maybe String]
However, I try
type M a = Maybe a
type MList' = MapT M '[Int, String]
It doesn't work.
I tried type family as well
type family M a
type instance M a = Maybe a
but It still doesn't work, saying
`Type synonym `M` should have 1 argument.
Is there a way to solve this without having to create a new datatype (or new type) ?
Unfortunately there is no way to solve this without having to create a new datatype (or newtype). What you are looking for seems to be a type-level lambda (like you have in many formal Haskell-related calculi like System Fw and its extensions), but Haskell unfortunately does not have type-level lambdas. Type synonyms may look like they could be used for this, but unfortunately, they must be fully-applied when they are mentioned. You need to use a newtype or data type instead, as you mentioned yourself..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With