Is it possible to define type that enchances record with maybe

Hello all,

I’m curious if it is possible in purescript to do something like derive type from record that add to all fields maybe, for instance

type Person = { name :: String, age :: Number }

-- Something Person that will result in type { name :: Maybe String, age :: Maybe Number }

Is there way to do that?


You can template it out with higher-kinded type synonyms.

type PersonFields f =
  ( name :: f String
  , age :: f Number

-- You can pass synonyms like this to other type synonyms
type Unlifted a = a

type Person = { | PersonFields Unlifted }
type PersonMaybe = { | PersonFields Maybe }

There are more types you can use for f besides Maybe:


Thank you, thank link is very usefull

1 Like