blarney-0.1.0.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Blarney.TaggedUnion

Synopsis

Documentation

data TaggedUnion (fields :: [Type]) Source #

A abstract type for tagged unions. Example usage: > type Either a b = TaggedUnion ["left" ::: a, "right" ::: b]

Instances

Instances details
IsTaggedUnion (TaggedUnion fields) => Bits (TaggedUnion fields) #

Bits instance for tagged unions

Instance details

Defined in Blarney.TaggedUnion

Associated Types

type SizeOf (TaggedUnion fields) :: Nat Source #

Methods

sizeOf :: TaggedUnion fields -> Int Source #

pack :: TaggedUnion fields -> Bit (SizeOf (TaggedUnion fields)) Source #

unpack :: Bit (SizeOf (TaggedUnion fields)) -> TaggedUnion fields Source #

nameBits :: String -> TaggedUnion fields -> TaggedUnion fields Source #

(IsTaggedUnion (TaggedUnion members), FShowMember members) => FShow (TaggedUnion members) # 
Instance details

Defined in Blarney.TaggedUnion

Methods

fshow :: TaggedUnion members -> Format Source #

fshowList :: [TaggedUnion members] -> Format Source #

IsTaggedUnion (TaggedUnion members) => Interface (TaggedUnion members) # 
Instance details

Defined in Blarney.TaggedUnion

Methods

toIfc :: TaggedUnion members -> (IfcTerm, IfcType) Source #

fromIfc :: IfcTerm -> TaggedUnion members Source #

(Bits t, IsTaggedUnion (TaggedUnion rest), KnownSymbol tag) => IsTaggedUnion (TaggedUnion ((tag ::: t) ': rest)) # 
Instance details

Defined in Blarney.TaggedUnion

Associated Types

type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) tag Source #

Methods

getMembers :: TaggedUnion ((tag ::: t) ': rest) -> [(String, Int)] Source #

toRaw :: TaggedUnion ((tag ::: t) ': rest) -> (BV, BV) Source #

fromRaw :: (BV, BV) -> TaggedUnion ((tag ::: t) ': rest) Source #

IsTaggedUnion (TaggedUnion ('[] :: [Type])) # 
Instance details

Defined in Blarney.TaggedUnion

Associated Types

type GetMemberType (TaggedUnion '[]) tag Source #

Methods

getMembers :: TaggedUnion '[] -> [(String, Int)] Source #

toRaw :: TaggedUnion '[] -> (BV, BV) Source #

fromRaw :: (BV, BV) -> TaggedUnion '[] Source #

type SizeOf (TaggedUnion fields) # 
Instance details

Defined in Blarney.TaggedUnion

type SizeOf (TaggedUnion fields)
type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) name # 
Instance details

Defined in Blarney.TaggedUnion

type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) name = If (tag == name) t (GetMemberType (TaggedUnion rest) name)
type GetMemberType (TaggedUnion ('[] :: [Type])) name # 
Instance details

Defined in Blarney.TaggedUnion

type GetMemberType (TaggedUnion ('[] :: [Type])) name = TypeError (('Text "TaggedUnion: tag " :<>: 'ShowType name) :<>: 'Text " doesn't exist") :: Type

data TagName (sym :: Symbol) Source #

Wrapper for field name symbols

Instances

Instances details
sym0 ~ sym1 => IsLabel sym0 (TagName sym1) #

Tag names are labels

Instance details

Defined in Blarney.TaggedUnion

Methods

fromLabel :: TagName sym1 #

data (a :: Symbol) ::: (b :: Type) Source #

For specifying the type of a named field of a tagged union

Instances

Instances details
(Bits t, IsTaggedUnion (TaggedUnion rest), KnownSymbol tag) => IsTaggedUnion (TaggedUnion ((tag ::: t) ': rest)) # 
Instance details

Defined in Blarney.TaggedUnion

Associated Types

type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) tag Source #

Methods

getMembers :: TaggedUnion ((tag ::: t) ': rest) -> [(String, Int)] Source #

toRaw :: TaggedUnion ((tag ::: t) ': rest) -> (BV, BV) Source #

fromRaw :: (BV, BV) -> TaggedUnion ((tag ::: t) ': rest) Source #

type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) name # 
Instance details

Defined in Blarney.TaggedUnion

type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) name = If (tag == name) t (GetMemberType (TaggedUnion rest) name)

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 #

Associated Types

type GetMemberType t (tag :: Symbol) :: Type Source #

Methods

getMembers :: t -> [(String, Int)] Source #

toRaw :: t -> (BV, BV) Source #

fromRaw :: (BV, BV) -> t Source #

Instances

Instances details
(Bits t, IsTaggedUnion (TaggedUnion rest), KnownSymbol tag) => IsTaggedUnion (TaggedUnion ((tag ::: t) ': rest)) # 
Instance details

Defined in Blarney.TaggedUnion

Associated Types

type GetMemberType (TaggedUnion ((tag ::: t) ': rest)) tag Source #

Methods

getMembers :: TaggedUnion ((tag ::: t) ': rest) -> [(String, Int)] Source #

toRaw :: TaggedUnion ((tag ::: t) ': rest) -> (BV, BV) Source #

fromRaw :: (BV, BV) -> TaggedUnion ((tag ::: t) ': rest) Source #

IsTaggedUnion (TaggedUnion ('[] :: [Type])) # 
Instance details

Defined in Blarney.TaggedUnion

Associated Types

type GetMemberType (TaggedUnion '[]) tag Source #

Methods

getMembers :: TaggedUnion '[] -> [(String, Int)] Source #

toRaw :: TaggedUnion '[] -> (BV, BV) Source #

fromRaw :: (BV, BV) -> TaggedUnion '[] Source #