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
- class HMaybied r r' | r -> r' where
- hMaybied :: r -> r'
- mkVariant :: (RecordLabels v ls, HFind x ls n, HMaybied v v', HUpdateAtHNat n (LVPair x (Maybe y)) v' v') => x -> y -> Record v -> Variant v'
- unVariant :: (RecordLabels v ls, HFind x ls n, HLookupByHNat n v (LVPair x (Maybe y))) => x -> Variant v -> Maybe y
Variant types on the basis of label-maybe pairs.
Turn proxy sequence into sequence of Nothings