[Haskell-cafe] creating a type based on a string
gcross at phys.washington.edu
Thu Sep 2 16:47:19 EDT 2010
What is stopping you from using an enumeration type?
data Tag = A | B
data X = X String Tag
op "a" = X "a" A
op "b" = X "b" B
On 9/2/10 1:31 PM, Andrew U. Frank wrote:
> I have a user input (string) and need to select one of two types.
> depending what the input is. is this possible?
> data A
> data B
> data X n = X String
> op :: String -> X n
> op "a" = X "a" :: X A
> op "b" = X "b" :: X B
> this does obviously not compile. is there a way to achieve that the type
> X A is produced when the input is "a" and X B when the input is "b"?
> thank you for help!
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe