<br><br><div class="gmail_quote">On Mon, Jun 8, 2009 at 4:10 PM, Henry Laxen <span dir="ltr">&lt;<a href="mailto:nadine.and.henry@pobox.com">nadine.and.henry@pobox.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Lets suppose I have a file that has encoded things of different<br>
types as integers, and now I would like to convert them back<br>
into specific instances of a data type.  For example, I have a<br>
file that contains 1,1,2,3 and I would like the output to be<br>
[Red, Red, Green, Blue]. I also would like to do this<br>
generically, so that if I wanted to convert the same list of<br>
integers into say Sizes, I would get [Small, Small, Medium,<br>
Large]  Now please have a look at the following code:<br>
<br>
{-# LANGUAGE DeriveDataTypeable #-}<br>
import Data.Generics<br>
data Color = Red | Green | Blue deriving (Eq,Ord,Read,Show,Typeable,Data)<br>
data Size  = Small | Mediaum | Large deriving (Eq,Ord,Read,Show,Typeable,Data)</blockquote><div><br>What about making both of these instances of Enum instead of using Data and Typeable?<br><br>You&#39;d get fromEnum and toEnum.  Which I think, would give you the int mapping that you are after.<br>
<br>fromEnum :: Enum a =&gt; a -&gt; Int<br>toEnum :: Enum a =&gt; Int -&gt; a<br><br>Jason<br></div></div><br>