
Hi Niklas, On Mon, Mar 10, 2014 at 02:59:36PM +0100, Niklas Haas wrote:
On Mon, 10 Mar 2014 14:54:14 +0100, Niklas Haas
wrote: 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.)
Oops, you are asking about the other direction. Well, you're in luck here too - Data has readConstr :: DataType -> String -> Maybe Constr.
Great! But how do I recover the actual constructor? E.g., f :: String -> Constr f s = fromMaybe (error "error in f") $ readConstr (dataTypeOf $ B 1) s gives me back Data.Data.Constr (not D). I was hoping for something along the lines f "A" $ 1 to get back a value A 1 of type D, etc. Many thanks, S. -- Семен Тригубенко http://trygub.com