You are probably looking for the generics functionality available in the module Data.Data
. If you define a data type with a derived instance Data
, for example:
{-# LANGUAGE DeriveDataTypeable #-}
import Data.Data
data Foo = Bar1 Int
| Bar2 String String
| Bar3 Double
deriving (Data)
toConstr
:
> toConstr (Bar1 1)
Bar1
> toConstr (Bar2 "hello" "there")
Bar2
>
Constr
, , :
checkConst :: (Data g) => g -> g -> Bool
checkConst x y = toConstr x == toConstr y
:
> checkConst (Bar1 10) (Bar1 20)
True
> checkConst (Bar1 10) (Bar3 20)
False
>