Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use type synonym in type declaration mapping

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) ?

like image 478
mb14 Avatar asked Apr 24 '26 20:04

mb14


1 Answers

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..

like image 60
Dominique Devriese Avatar answered Apr 26 '26 13:04

Dominique Devriese