Extracting constructor name
hesselink at gmail.com
Tue Sep 27 18:56:00 CEST 2011
You can use Data.Data, and the DeriveDataTypeable extension. If you
say "deriving Typeable, Data" on your data type, you can use toConstr
to get a constructor representation. See also the documentation .
P.S. Shouldn't this be on -cafe?
On Tue, Sep 27, 2011 at 18:40, Gracjan Polak <gracjanpolak at gmail.com> wrote:
> Hi all,
> To get a bit better error reporting and debugging I'd like to report constructor
> names misused. Example:
> data X = A | B Int | C String
> magic A = doSomething
> magic x = error $ "magic can only be used on A, you supplied " ++ constrName x
> I'm missing constrName that returns only constructor name as string, skips all
> fields (if any).
> Libraries mailing list
> Libraries at haskell.org
More information about the Libraries