Extracting constructor name

Felipe Almeida Lessa felipe.lessa at gmail.com
Tue Sep 27 18:44:33 CEST 2011

There's the obvious approach

  class ConstrName a where
    constrName :: a -> String

  instance ConstrName X where
    constrName A   = "A"
    constrName B{} = "B"
    constrName C{} = "C"

You could automate the instance creating using Template Haskell, to
get something like

  data X = ...
  deriveConstrName 'X

I don't know if there's a more generic way.



More information about the Libraries mailing list