Safe Haskell | None |
---|---|

Language | Haskell2010 |

Sometimes one needs a type like
`Barbie `

and it may feel like
a second-class record type, where one needs to
unpack values in each field. For those cases, we can leverage on
closed type-families:`Identity`

data`Bare`

data`Covered`

type family`Wear`

t f a where`Wear`

`Bare`

f a = a`Wear`

`Covered`

f a = f a data SignUpForm t f = SignUpForm' { username ::`Wear`

t f`String`

, , password ::`Wear`

t f`String`

, mailingOk ::`Wear`

t f`Bool`

} instance`FunctorB`

(SignUpForm`Covered`

) instance`TraversableB`

(SignUpForm`Covered`

) ..., instance`BareB`

SignUpForm type SignUpRaw = SignUpForm`Maybe`

type SignUpData = SignUpForm`Bare`

formData = SignUpForm "jbond" "shaken007" False :: SignUpData

# Bare values

type family Wear t f a where ... Source #

The `Wear`

type-function allows one to define a Barbie-type as

data B t f = B { f1 ::`Wear`

t f`Int`

, f2 ::`Wear`

t f`Bool`

}

This gives rise to two rather different types:

`B`

is a normal Barbie-type, in the sense that`Covered`

f`f1 :: B`

, etc.`Covered`

f -> f`Int`

`B`

, on the other hand, is a normal record with no functor around the type:`Bare`

f

B { f1 :: 5, f2 =`True`

} :: B`Bare`

f

# Covering and stripping

class FunctorB (b Covered) => BareB b where Source #

Class of Barbie-types defined using `Wear`

and can therefore
have `Bare`

versions. Must satisfy:

`bcover`

.`bstrip`

=`id`

`bstrip`

.`bcover`

=`id`

Nothing