[Haskell-cafe] Enum to String, and back?
michael rice
nowgate at yahoo.com
Wed Apr 15 21:48:55 EDT 2009
Thanks guys. It works like a charm.
Michael
--- On Wed, 4/15/09, Rahul Kapoor <rk at trie.org> wrote:
From: Rahul Kapoor <rk at trie.org>
Subject: Re: [Haskell-cafe] Enum to String, and back?
To:
Cc: haskell-cafe at haskell.org
Date: Wednesday, April 15, 2009, 3:20 PM
On Wed, Apr 15, 2009 at 3:13 PM, michael rice <nowgate at yahoo.com> wrote:
> Using Show it is possible to establish a relationship between an enum type
> and a String type to display it.
> Can one as easily establish a reverse relationship, i.e., convert a String
> type like "Red" back to its corresponding Color type?
>
Make it an instance of the Read type class.
http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t%3ARead
That will allow you to write -
read "Red" :: Color
=> Red
HTH
Rahul
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090415/7febb915/attachment.htm
More information about the Haskell-Cafe
mailing list