{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
module Clash.Core.DataCon
( DataCon (..)
, DcName
, ConTag
)
where
import Control.DeepSeq (NFData(..))
import Data.Binary (Binary)
import Data.Hashable (Hashable)
import qualified Data.Text as Text
import GHC.Generics (Generic)
import Clash.Core.Name (Name (..))
import {-# SOURCE #-} Clash.Core.Type (Type)
import Clash.Core.Var (TyVar)
import Clash.Unique
import Clash.Util
data DataCon
= MkData
{ dcName :: !DcName
, dcUniq :: {-# UNPACK #-} !Unique
, dcTag :: !ConTag
, dcType :: !Type
, dcUnivTyVars :: [TyVar]
, dcExtTyVars :: [TyVar]
, dcArgTys :: [Type]
, dcFieldLabels :: [Text.Text]
} deriving (Generic,NFData,Hashable,Binary)
instance Show DataCon where
show = show . dcName
instance Eq DataCon where
(==) = (==) `on` dcUniq
(/=) = (/=) `on` dcUniq
instance Ord DataCon where
compare = compare `on` dcUniq
instance Uniquable DataCon where
getUnique = dcUniq
setUnique dc u = dc {dcUniq=u, dcName=(dcName dc){nameUniq=u}}
type ConTag = Int
type DcName = Name DataCon