[Haskell-cafe] Enum to String, and back?
Martijn van Steenbergen
martijn at van.steenbergen.nl
Wed Apr 15 15:17:26 EDT 2009
Hi Michael,
michael rice wrote:
> Can one as easily establish a reverse relationship, i.e., convert a
> String type like "Red" back to its corresponding Color type?
>
> So that
>
> "Red" :: [Char] -> Red :: Color
Yes, simply add Read to your list of to be derived type classes. Then
you can say:
> read "Red" :: Color
HTH,
Martijn.
More information about the Haskell-Cafe
mailing list