superrecord-0.5.0.0: Supercharged anonymous records

Safe HaskellNone
LanguageHaskell2010

SuperRecord.Variant.Tagged

Synopsis

Documentation

type TaggedVariant opts = Variant opts Source #

Just a type alias vor Variant

toTaggedVariant :: forall opts lbl a pos. (KnownSymbol lbl, VariantMember (lbl := a) opts, KnownNat pos, VariantPos (lbl := a) opts ~ pos) => FldProxy lbl -> a -> TaggedVariant opts Source #

Helper function to construct a tagged variant value given the tag and the value. Note that you can use OverloadedLabels for nicer syntax to construct the FldProxy.

toTaggedVariant #myTag "myValue"

fromTaggedVariant :: forall opts lbl a pos. (KnownSymbol lbl, VariantMember (lbl := a) opts, KnownNat pos, VariantPos (lbl := a) opts ~ pos) => FldProxy lbl -> TaggedVariant opts -> Maybe a Source #

Convert a variant back to a common Haskell type. Returns nothing if the variant is not of the right tag and type.

taggedVariantCase :: forall lbl t ts r. FldProxy lbl -> (t -> r) -> VariantMatch r ts -> VariantMatch r ((lbl := t) ': ts) Source #

Nicer syntax for VariantCase for tagged variants.

newtype JsonTaggedVariant opts Source #

Newtype wrapper for TaggedVariant which provides a useful JSON encoding of tagged variants in the form {"tag": value}