[Haskell-cafe] Constructing a datatype given just its constructor
as a string?
benja.fallenstein at gmail.com
Mon Jun 25 03:04:54 EDT 2007
2007/6/25, Donald Bruce Stewart <dons at cse.unsw.edu.au>:
> > 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:
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
More information about the Haskell-Cafe