Lazy bind...

Martin Norbäck d95mback@dtek.chalmers.se
30 Jul 2002 14:48:59 +0200


--=-aZIj3XVZjEuJAFLlFmUu
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

tis 2002-07-30 klockan 14.41 skrev MR K P SCHUPKE:
>=20
> Is there any way to do a lazy bind operation, something like
>=20
>     a <- $ getLine
>     return (Constructor $ a)
>=20
> this works for computations in the IO monad :-
>=20
>     a <- unsafeInterleaveIO getLine
>     return (Constructor $ a)
>=20
> but I need to do this for a general monad M.

Remember that the syntax

  a <- getLine
  return (Constructor a)

is just sugar for

  getLine >>=3D \a -> return (Constructor a)

so actually the bind is already lazy (lamba binding is lazy). The
laziness of the construction here will depend on your definition of >>=3D
for the monad in question. Since the point of the IO monad is to
sequentialize IO operations, >>=3D will definititely not be lazy there.

Perhaps if you give a concrete example of what you want to do, people
could help you more.

Regards,

	Martin

--=20
Martin Norb=E4ck          d95mback@dtek.chalmers.se             =20
Kapplandsgatan 40       +46 (0)708 26 33 60                   =20
S-414 78  G=D6TEBORG      http://www.dtek.chalmers.se/~d95mback/
SWEDEN                  OpenPGP ID: 3FA8580B

--=-aZIj3XVZjEuJAFLlFmUu
Content-Type: application/pgp-signature; name=signature.asc

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: För information se http://www.gnupg.org/

iD8DBQA9Ros7kXyAGj+oWAsRApeBAJsGu3iEMsnkXaLUV6qfSkFXb6LW4ACghphH
0navEaxgWarcoaMSjcWmEQs=
=Ub0+
-----END PGP SIGNATURE-----

--=-aZIj3XVZjEuJAFLlFmUu--