module DDC.Core.Exp.DaCon
( DaCon (..)
, dcUnit
, takeNameOfDaCon
, takeTypeOfDaCon)
where
import DDC.Type.Compounds
import DDC.Type.Exp
import Control.DeepSeq
data DaCon n
= DaConUnit
| DaConPrim
{
daConName :: !n
, daConType :: !(Type n)
}
| DaConBound
{
daConName :: !n
}
deriving (Show, Eq)
instance NFData n => NFData (DaCon n) where
rnf !dc
= case dc of
DaConUnit -> ()
DaConPrim n t -> rnf n `seq` rnf t
DaConBound n -> rnf n
takeNameOfDaCon :: DaCon n -> Maybe n
takeNameOfDaCon dc
= case dc of
DaConUnit -> Nothing
DaConPrim{} -> Just $ daConName dc
DaConBound{} -> Just $ daConName dc
takeTypeOfDaCon :: DaCon n -> Maybe (Type n)
takeTypeOfDaCon dc
= case dc of
DaConUnit -> Just $ tUnit
DaConPrim{} -> Just $ daConType dc
DaConBound{} -> Nothing
dcUnit :: DaCon n
dcUnit = DaConUnit