the standard function enumFrom
"Paqui Lucio" <[email protected]> Mon, 25 Oct 2010 17:12:45 +0200
| Newsgroups | gmane.comp.lang.haskell.hugs.user |
|---|---|
| Message-ID | <D58BAD2CB7AF416D8AFE9B82227B8EAF@SIPC64> |
This is a multi-part message in MIME format.
--===============0864760161==
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_003B_01CB7467.D79E4B40"
This is a multi-part message in MIME format.
------=_NextPart_000_003B_01CB7467.D79E4B40
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
Given the following enumerated type (as an example)
data P =3D A | B | C | D | E=20
deriving (Show,Enum)
and the Prelude definition:=20
enumFrom x =3D map toEnum [ fromEnum x ..]
I guess that the two expressions=20
1) (map toEnum [ fromEnum A ..]) :: [P]
2) enumFrom A=20
should produces the same result, say=20
[A,B,C,D,E] :: [P]=20
However, the expression 1) produces an error as a consequence of trying =
to
apply toEnum to the number 5.
=BFWhy the expression 2) doesn't not produce the same error?
=BFDoes Hugs not apply the definition in the Prelude for evaluating the
expression 2)?
There should be something that I'm missing in this computation.=20
Some hints?
Thanks in advance,
Paqui
---------------------------------=20
Paqui Lucio =20
Dpto de LSI =20
Facultad de Inform=E1tica
Paseo Manuel de Lardizabal, 1
20080-San Sebasti=E1n
SPAIN
---------------------------------
e-mail: [email protected]
Tfn: (+34) (9)43 015049 =20
Fax: (+34) (9)43 015590
Web: http://www.sc.ehu.es/paqui
---------------------------------
------=_NextPart_000_003B_01CB7467.D79E4B40
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.5.7036.0">
<TITLE>the standard function enumFrom</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">Hi,</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">Given the following =
enumerated type (as an example)</FONT></SPAN>
</P>
<P><SPAN LANG=3D"es"><FONT FACE=3D"Courier New">data P =3D A | B | C | D =
| E </FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT FACE=3D"Courier =
New"> deriving =
(Show,Enum)</FONT></SPAN>
</P>
<P><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">and the Prelude =
definition: </FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT FACE=3D"Courier =
New"> =
enumFrom x =3D map toEnum [ fromEnum x ..]</FONT></SPAN>
</P>
<P><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">I guess that =
the two expressions </FONT></SPAN>
<BR><SPAN LANG=3D"es"> <FONT =
FACE=3D"Times New Roman">1)</FONT> <FONT FACE=3D"Courier New">(map =
toEnum [ fromEnum A ..]) :: [P]</FONT></SPAN>
<BR><SPAN LANG=3D"es"> <FONT =
FACE=3D"Times New Roman">2) </FONT> <FONT FACE=3D"Courier =
New">enumFrom A </FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">should produces the =
same result, say </FONT></SPAN>
<BR><SPAN LANG=3D"es"> <FONT =
FACE=3D"Courier New">[A,B,C,D,E] :: [P] </FONT></SPAN>
</P>
<P><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">However, the =
expression 1) produces an error as a consequence of trying to =
apply toEnum to the number 5.</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">=BFWhy the =
expression 2) doesn't not produce the same error?</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">=BFDoes Hugs not =
apply the definition in the Prelude for evaluating the expression =
2)?</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">There should be =
something that I'm missing in this computation. </FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">Some =
hints?</FONT></SPAN>
</P>
<P><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">Thanks in =
advance,</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT FACE=3D"Times New Roman">Paqui</FONT></SPAN>
</P>
<P><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier =
New">--------------------------------- </FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier New">Paqui =
Lucio &n=
bsp; &nb=
sp; </FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier New">Dpto de =
LSI &nbs=
p; </FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier New">Facultad de =
Inform=E1tica</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier New">Paseo Manuel =
de Lardizabal, 1</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier New">20080-San =
Sebasti=E1n</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier =
New">SPAIN</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier =
New">---------------------------------</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier New">e-mail: =
[email protected]</FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier New">Tfn: (+34) =
(9)43 015049 </FONT></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier New">Fax: (+34) =
(9)43 015590</FONT></SPAN>
<BR><SPAN LANG=3D"en-gb"><FONT SIZE=3D2 FACE=3D"Courier New">Web: =
</FONT></SPAN><A HREF=3D"http://www.sc.ehu.es/paqui"><SPAN =
LANG=3D"en-gb"><U><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Courier =
New">http://www.sc.ehu.es/paqui</FONT></U></SPAN></A><SPAN =
LANG=3D"en-gb"></SPAN>
<BR><SPAN LANG=3D"es"><FONT SIZE=3D2 FACE=3D"Courier =
New">---------------------------------</FONT></SPAN><SPAN =
LANG=3D"es"></SPAN>
</P>
</BODY>
</HTML>
------=_NextPart_000_003B_01CB7467.D79E4B40--
--===============0864760161==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Hugs-Users mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/hugs-users
--===============0864760161==--