Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data TaggedUnion (fields :: [Type])
- data TagName (sym :: Symbol)
- data (a :: Symbol) ::: (b :: Type)
- module GHC.OverloadedLabels
- isTagged :: forall u name. (IsTaggedUnion u, KnownSymbol name) => u -> TagName name -> Bit 1
- is :: forall u name. (IsTaggedUnion u, KnownSymbol name) => u -> TagName name -> Bit 1
- tag :: forall name m u. (IsTaggedUnion u, KnownSymbol name, m ~ GetMemberType u name, Bits m) => TagName name -> m -> u
- untag :: (IsTaggedUnion u, KnownSymbol name, m ~ GetMemberType u name, Bits m) => TagName name -> u -> m
- untagDefault :: forall name m u. (IsTaggedUnion u, KnownSymbol name, m ~ GetMemberType u name, Bits m) => TagName name -> m -> u -> m
- whenTagged :: (IsTaggedUnion u, KnownSymbol name, m ~ GetMemberType u name, Bits m) => TagName name -> u -> (GetMemberType u name -> Action a) -> Action a
- class IsTaggedUnion t where
Documentation
data TaggedUnion (fields :: [Type]) Source #
A abstract type for tagged unions. Example usage: > type Either a b = TaggedUnion ["left" ::: a, "right" ::: b]
Instances
data (a :: Symbol) ::: (b :: Type) Source #
For specifying the type of a named field of a tagged union
Instances
(Bits t, IsTaggedUnion (TaggedUnion rest), KnownSymbol tag) => IsTaggedUnion (TaggedUnion ((tag ::: t) ': rest)) # | |
Defined in Blarney.TaggedUnion type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) tag Source # | |
type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) name # | |
Defined in Blarney.TaggedUnion type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) name = If (tag == name) t (GetMemberType (TaggedUnion rest) name) |
module GHC.OverloadedLabels
isTagged :: forall u name. (IsTaggedUnion u, KnownSymbol name) => u -> TagName name -> Bit 1 infix 7 Source #
Does given tagged union have given tag?
is :: forall u name. (IsTaggedUnion u, KnownSymbol name) => u -> TagName name -> Bit 1 infix 7 Source #
Shorthand for isTagged
tag :: forall name m u. (IsTaggedUnion u, KnownSymbol name, m ~ GetMemberType u name, Bits m) => TagName name -> m -> u Source #
Construct a value of a tagged union
untag :: (IsTaggedUnion u, KnownSymbol name, m ~ GetMemberType u name, Bits m) => TagName name -> u -> m Source #
Get the value of given field if the tag matches. If tag doesn't
match, return dontCare
.
untagDefault :: forall name m u. (IsTaggedUnion u, KnownSymbol name, m ~ GetMemberType u name, Bits m) => TagName name -> m -> u -> m Source #
Get the value of given field if the tag matches. If tag doesn't match, return default value.
whenTagged :: (IsTaggedUnion u, KnownSymbol name, m ~ GetMemberType u name, Bits m) => TagName name -> u -> (GetMemberType u name -> Action a) -> Action a Source #
Conditional statement for tagged unions
class IsTaggedUnion t where Source #
type GetMemberType t (tag :: Symbol) :: Type Source #
Instances
(Bits t, IsTaggedUnion (TaggedUnion rest), KnownSymbol tag) => IsTaggedUnion (TaggedUnion ((tag ::: t) ': rest)) # | |
Defined in Blarney.TaggedUnion type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) tag Source # | |
IsTaggedUnion (TaggedUnion ('[] :: [Type])) # | |
Defined in Blarney.TaggedUnion type GetMemberType (TaggedUnion '[]) tag Source # getMembers :: TaggedUnion '[] -> [(String, Int)] Source # |