Evaluation order, ghc versus hugs, lazy vs. strict

Dylan Thurston dpt@math.harvard.edu
Mon, 19 Aug 2002 23:38:42 -0400


--IiVenqGWf+H9Y6IX
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Aug 19, 2002 at 11:34:48PM +0100, Alastair Reid wrote:
>=20
> > main =3D print $ sum [0..1000000]
> ...
> Hugs uses foldl' instead of foldl to define sum:...

Does it really?  That's a violation of the standard: a user's instance
of (+) need not be strict in its left argument.  Consider

> data Foo =3D Foo Integer deriving (Eq, Show)

> instance Num Foo where
>   fromInteger =3D Foo
>   a + b =3D b

> v1 =3D undefined + Foo 2
> v2 =3D sum [undefined, Foo 2]

Both v1 and v2 should have the value 'Foo 2'.  However, hugs (December
2001) gives=20

Program error: {undefined}

in response to v2.  ghci gets it right.

--Dylan

--IiVenqGWf+H9Y6IX
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9YbnCVeybfhaa3tcRAiO6AJ42jsuIJPkIQLQCxlo8dEShqtTQMQCfYXFb
65PvySxrrHH8SEM5eBK00g4=
=N48Y
-----END PGP SIGNATURE-----

--IiVenqGWf+H9Y6IX--