Package

purescript-untagged-to-tagged

Repository
sigma-andex/purescript-untagged-to-tagged
License
MIT-0
Uploaded by
pacchettibotti
Published on
2022-12-10T09:15:51Z

Little helper library to make it easy to convert between untagged and tagged unions.

Installation

spago install untagged-to-tagged

Usage

Convert an untagged union to a tagged union. E.g.

type ISU
  = Int |+| String

data IST
  = IT Int
  | ST String

-- generic instance is needed for the conversion
derive instance Generic IST _

instance Show IST where
  show = genericShow

isul :: ISU
isul = asOneOf 10

isur :: ISU
isur = asOneOf "Wurst"

istl :: IST
istl = toTagged isul 
-- IT 10

istr :: IST 
istr = toTagged isur 
-- ST "Wurst"

Convert a tagged union to an untagged union. E.g.

data IST = IT Int | ST String 
derive instance Generic IST _ 

type ISU = Int |+| String 

ist :: IST
ist = ST "Wurst"

isu :: ISU 
isu = fromTagged ist
-- asOneOf "Wurst"