[Haskell-cafe] Constructing a datatype given just its constructor as a string?

Benja Fallenstein benja.fallenstein at gmail.com
Mon Jun 25 03:04:54 EDT 2007


Hi Hugh,

2007/6/25, Donald Bruce Stewart <dons at cse.unsw.edu.au>:
> hughperkins:
> >
> >    Just noticed that all my responses have been going only to
> >    Neil, not  to the group.
> >    Anyway, the jist of our conversation was that it's not
> >    possible to create arbitrary datatypes/constructors from
> >    strings in Haskell.  Can anyone deny/confirm?
>
> Anyway there was a thread on this last week.

That thread starting here:

http://www.haskell.org/pipermail/haskell-cafe/2007-June/026777.html

The takeaway was Stefan O'Rear's suggestion that if you don't want to
create a table of datatypes manually, you can use hs-plugins --
something along the lines of

data Foo = forall a. MyClass a => Foo a
read' typeName s = eval ("Foo (gread \"" ++ s ++ "\" :: " ++ typeName
++ ")") :: Foo

- Benja


More information about the Haskell-Cafe mailing list