superrecord-0.5.1.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}

Instances
(KnownSymbol lbl, ToJSON t, ToJSON (JsonTaggedVariant ts)) => ToJSON (JsonTaggedVariant ((lbl := t) ': ts)) Source # 
Instance details

Defined in SuperRecord.Variant.Tagged

Methods

toJSON :: JsonTaggedVariant ((lbl := t) ': ts) -> Value #

toEncoding :: JsonTaggedVariant ((lbl := t) ': ts) -> Encoding #

toJSONList :: [JsonTaggedVariant ((lbl := t) ': ts)] -> Value #

toEncodingList :: [JsonTaggedVariant ((lbl := t) ': ts)] -> Encoding #

ToJSON (JsonTaggedVariant ([] :: [Type])) Source # 
Instance details

Defined in SuperRecord.Variant.Tagged

(FromJSON t, FromJSON (JsonTaggedVariant ts), KnownSymbol lbl) => FromJSON (JsonTaggedVariant ((lbl := t) ': ts)) Source # 
Instance details

Defined in SuperRecord.Variant.Tagged

Methods

parseJSON :: Value -> Parser (JsonTaggedVariant ((lbl := t) ': ts)) #

parseJSONList :: Value -> Parser [JsonTaggedVariant ((lbl := t) ': ts)] #

FromJSON (JsonTaggedVariant ([] :: [Type])) Source # 
Instance details

Defined in SuperRecord.Variant.Tagged