Module

Data.TaggedSum.Internal

Package
purescript-tagged-sum
Repository
lumihq/purescript-tagged-sum

#Any Source

data Any :: Type

#TaggedSum Source

newtype TaggedSum (r :: Row Type)

A sum type, whose tag is one of the labels in the row r, with a value of the corresponding type.

Constructors

Instances

#getTag Source

getTag :: forall r. TaggedSum r -> String

Get the tag for a TaggedSum.

#case_ Source

case_ :: forall r a t s. Prism s t a Void -> (a -> r) -> (t -> r) -> s -> r

Match a particular tag using a Prism.

See match.

#AllVoid Source

class AllVoid (rl :: RowList) 

Instances

#match Source

match :: forall x rl r. RowToList r rl => AllVoid rl => TaggedSum r -> x

Pattern match an empty variant, once all possible tags have been handled using case_.

For example:

x :: TaggedSum (foo :: Int, bar :: Char)
x = review (tag (SProxy :: SProxy "foo")) 42

f :: TaggedSum (foo :: Int, bar :: Char) -> String
f = match
  # case_ (tag (SProxy :: SProxy "foo")) show
  # case_ (tag (SProxy :: SProxy "bar")) show

> f x
"42"

#tag Source

tag :: forall r_ b a t s tag. IsSymbol tag => Cons tag a r_ s => Cons tag b r_ t => SProxy tag -> Prism (TaggedSum s) (TaggedSum t) a b

Create a Prism for accessing a specific tag.

#tag_ Source

tag_ :: forall r_ r a tag. IsSymbol tag => Cons tag a r_ r => SProxy tag -> Prism' (TaggedSum r) a

A simpler, non-type changing Prism, which might make type inference possible in some cases.

#cotag Source

cotag :: forall a t_ s_ t s tag. IsSymbol tag => Cons tag a s_ s => Cons tag a t_ t => SProxy tag -> Prism (TaggedSum s) (TaggedSum t) (TaggedSum s_) (TaggedSum t_)

Create a Prism for accessing the complement of a specific tag.

#cotag_ Source

cotag_ :: forall r_ r a tag. IsSymbol tag => Cons tag a r_ r => SProxy tag -> Prism' (TaggedSum r) (TaggedSum r_)

A simpler, non-type changing Prism, which might make type inference possible in some cases.

#DecodeHelper Source

class DecodeHelper (r :: Row Type) (rl :: RowList) | rl -> r where

Members

Instances

#EncodeHelper Source

class EncodeHelper (r :: Row Type) (rl :: RowList) | rl -> r where

Members

Instances