
10 Mar
2014
10 Mar
'14
9:54 a.m.
On Mon, 10 Mar 2014 13:11:25 +0000, Semen Trygubenko / Семен Тригубенко
Dear Haskell-cafe,
When deriving (Read), only values can be read in. If one wants to be able to read in constructors, too, is there an easy way out? E.g., the code below works, but the extra book-keeping
f "A" = A ...
is unpleasant — perhaps there's a simpler solution?
You can derive Data using the DeriveDataTypeable extension and then use the toConstr :: Data a => a -> Constr method to obtain the Constr (which has a Show instance that in this case just returns "A", "B" etc.)