No subject
Tue Nov 30 21:47:11 CET 2010
and gives a single constructor for doing so.
From: http://www.haskell.org/tutorial/moretypes.html=20
=A0 newtype Natural =3D MakeNatural Integer
=A0 This creates an entirely new type, Natural, whose only constructor cont=
ains
=A0 a single Integer. The constructor MakeNatural converts between an Natur=
al and
=A0 an Integer:
toNatural=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 :: Integer -> Natural
toNatural x | x < 0=A0=A0=A0=A0 =3D error "Can't create negative naturals!"=
=20
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 | otherwise =3D MakeNatural x
fromNatural=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 :: Natural -> Integer
fromNatural (MakeNatural i) =3D i
In the above case the existing type is Integer. The new type behaves like t=
he existing type, but we can pattern match with the new type.
++++++++++
In the case of ReaderT and StateT
newtype ReaderT r m a =3D ReaderT {
=A0=A0=A0=A0=A0=A0=A0 -- | The underlying computation, as a function of the=
environment.
=A0=A0=A0=A0=A0=A0=A0 runReaderT :: r -> m a
=A0=A0=A0 }
newtype StateT s m a =3D StateT { runStateT :: s -> m (a, s) }
what is the existing type?
Michael
--- On Wed, 12/29/10, Ryan Ingram <ryani.spam at gmail.com> wrote:
From: Ryan Ingram <ryani.spam at gmail.com>
Subject: Re: [Haskell-cafe] Reader monad
To: "michael rice" <nowgate at yahoo.com>
Cc: haskell-cafe at haskell.org
Date: Wednesday, December 29, 2010, 11:11 AM
On Wed, Dec 29, 2010 at 8:06 AM, michael rice <nowgate at yahoo.com> wrote:
> Is there an unparameterizable reader monad?
I'm not sure this is the answer you are looking for, but it seems like the =
obvious one.
=0A
Pick an "r", say "String".=A0 Now=A0 "Reader String" is an unparameterizabl=
e reader monad that passes around a String.
=A0 -- ryan
=0A=0A=0A=0A
--0-1258383414-1293642466=:80085
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
<table cellspacing=3D"0" cellpadding=3D"0" border=3D"0" ><tr><td valign=3D"=
top" style=3D"font: inherit;">Hi, Ryan.<br><br>Since I'm trying to understa=
nd Reader, I wanted to be aware of all cases of Reader. <br><br>=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>From the docs (and tuts) newtype creates=
a new type out of an existing type<br>and gives a single constructor for d=
oing so.<br><br><br>From: http://www.haskell.org/tutorial/moretypes.html <b=
r><br> newtype Natural =3D MakeNatural Integer<br><br> This cre=
ates an entirely new type, Natural, whose only constructor contains<br>&nbs=
p; a single Integer. The constructor MakeNatural converts between an Natura=
l and<br> an Integer:<br><br>toNatural &=
nbsp; :: Integer -> Natu=
ral<br>toNatural x | x < 0 =3D error "Can't crea=
te negative naturals!" <br> =
|
otherwise =3D MakeNatural x<br><br>fromNatural &nbs=
p; :: Natural -> Integer<br>fr=
omNatural (MakeNatural i) =3D i<br><br><br>In the above case the existing t=
ype is Integer. The new type behaves like the existing type, but we can pat=
tern match with the new type.<br><br>++++++++++<br><br>In the case of Reade=
rT and StateT<br><br>newtype ReaderT r m a =3D ReaderT {<br> &nb=
sp; -- | The underlying computation, as a function =
of the environment.<br> runReader=
T :: r -> m a<br> }<br><br>newtype StateT s m a =3D St=
ateT { runStateT :: s -> m (a, s) }<br><br>what is the existing type?<br=
><br>Michael<br><br>--- On <b>Wed, 12/29/10, Ryan Ingram <i><ryani.spam@=
gmail.com></i></b> wrote:<br><blockquote style=3D"border-left: 2px solid=
rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Ryan Ing=
ram
<ryani.spam at gmail.com><br>Subject: Re: [Haskell-cafe] Reader monad<b=
r>To: "michael rice" <nowgate at yahoo.com><br>Cc: haskell-cafe at haskell.=
org<br>Date: Wednesday, December 29, 2010, 11:11 AM<br><br><div id=3D"yiv35=
4267158">On Wed, Dec 29, 2010 at 8:06 AM, michael rice <span dir=3D"ltr">&l=
t;<a rel=3D"nofollow" ymailto=3D"mailto:nowgate at yahoo.com" target=3D"_blank=
" href=3D"/mc/compose?to=3Dnowgate at yahoo.com">nowgate at yahoo.com</a>></sp=
an> wrote:<br>> Is there an unparameterizable reader monad?<br><br>I'm n=
ot sure this is the answer you are looking for, but it seems like the obvio=
us one.<br>=0A<br>Pick an "r", say "String". Now "Reader String=
" is an unparameterizable reader monad that passes around a String.<br><br>=
-- ryan<br>=0A</div></blockquote></td></tr></table><br>=0A=0A
--0-1258383414-1293642466=:80085--
More information about the Haskell-Cafe
mailing list