Laziness
Dominic Steinitz
dominic.steinitz@blueyonder.co.uk
Sat, 2 Aug 2003 14:36:08 -0700
This is a multi-part message in MIME format.
------=_NextPart_000_0005_01C35903.69711B20
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Could someone explain to me why this doesn't work
test l =3D
hs
where
hs =3D map (\x -> [x]) [0..abs(l `div` hLen)]
hLen =3D length $ head hs
whereas this does
test l =3D
hs
where
hs =3D map (\x -> [x]) (0:[1..abs(l `div` hLen)])
hLen =3D length $ head hs
I would have thought laziness would allow the compiler to know that hs =
would contain at least one element and therefore calculate hLen.
Dominic.
------=_NextPart_000_0005_01C35903.69711B20
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Courier New" size=3D2>Could someone explain to me why =
this=20
doesn't work</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>test l =3D<BR> =20
hs<BR> =20
where<BR> hs =3D map (\x =
->=20
[x]) [0..abs(l `div` =
hLen)]<BR> =20
hLen =3D length $ head hs<BR></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>whereas this does</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>test l =3D<BR> =20
hs<BR> =20
where<BR> hs =3D map (\x =
->=20
[x]) (0:[1..abs(l `div`=20
hLen)])<BR> =
hLen =3D=20
length $ head hs<BR></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>I would have thought laziness =
would allow=20
the compiler to know that hs would contain at least one element and =
therefore=20
calculate hLen.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Dominic.</FONT><FONT =
face=3D"Courier New"=20
size=3D2></DIV></FONT>
<DIV><FONT face=3DArial size=3D2> </DIV></FONT>
<DIV><FONT face=3DArial size=3D2><BR></FONT> </DIV></BODY></HTML>
------=_NextPart_000_0005_01C35903.69711B20--