Safe Haskell | None |
---|
The HList library
(C) 2004, Oleg Kiselyov, Ralf Laemmel, Keean Schupke
Variants, i.e., labelled sums.
One approach to their implementation would be to consider both the favoured label and the corresponding value as dynamics upon variant construction. Since we are too lazy to programme some Typeable instances for non-ghc systems (NB: in GHC, Typeable is derivable), we rather model variants as (opaque) records with maybies for the values. Only one value will actually hold non-Nothing, as guaranteed by the constructor.
See VariantP.hs for a different approach to open sums.
- newtype Variant mr = Variant mr
- data HMaybeF = HMaybeF
- hMaybied :: (HMapAux HMaybeF as' bs', SameLength' * * as' bs', SameLength' * * bs' as') => HList as' -> HList bs'
- mkVariant :: (HFind k l (RecordLabels k r) n, HMapAux HMaybeF as' r, SameLength' * * as' r, SameLength' * * r as', HUpdateAtHNat n (Tagged k l (Maybe a)) r, ~ [*] (HUpdateAtHNatR n (Tagged k l (Maybe a)) r) r) => Label k l -> a -> Record as' -> Variant (HList r)
- unVariant :: HasField k l (Record r) v => Label k l -> Variant (HList r) -> v
Documentation
Variant types on the basis of label-maybe pairs.
Variant mr |
Turn proxy sequence into sequence of Nothings
hMaybied :: (HMapAux HMaybeF as' bs', SameLength' * * as' bs', SameLength' * * bs' as') => HList as' -> HList bs'Source
mkVariant :: (HFind k l (RecordLabels k r) n, HMapAux HMaybeF as' r, SameLength' * * as' r, SameLength' * * r as', HUpdateAtHNat n (Tagged k l (Maybe a)) r, ~ [*] (HUpdateAtHNatR n (Tagged k l (Maybe a)) r) r) => Label k l -> a -> Record as' -> Variant (HList r)Source
Public constructor
it seems we can blame hUpdateAtLabel
(not HMap
) for needing the asTypeOf?