If you only want to enumerate the constructors, you can you the Data.Data module, like so:
{-# LANGUAGE DeriveDataTypeable #-}
import Data.Data
data T a b = C1 a b | C2 deriving (Typeable, Data)
main = print $ constrIndex $ toConstr x
where
x :: T Int Int
x = C1 1 1 -- will print 1
-- x = C2 -- will print 2
If you don't want to go down the road of using the Typebale
and Data
type classes, you could also simply write a function Table -> Int
, like you proposed.