Help using a state monad
Chris Angus
CAngus@Armature.com
Mon, 14 Jan 2002 11:06:44 -0000
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C19CEB.8D51A3F0
Content-Type: text/plain;
charset="iso-8859-1"
your pattern match
of (s:sx) seems to be the cause of the delay
try
--Process the input
mProcess :: String -> State String
mProcess sx = do b <- isOn
if ( head sx == 't' )
then toggle
else return ()
appOut (tuUpper b (head sx)) (mProcess (tail sx))
instead
-----Original Message-----
From: Tom Bevan [mailto:tom@regex.com.au]
Sent: 14 January 2002 05:58
To: Haskell Cafe List
Subject: Help using a state monad
Hi all,
I'm trying to get a feel for how monads might be used in a Haskell
program and develop an approach that would be useful for larger
projects.
I have tried to model in miniture a programme which takes input from
'standard in' and processes it against an internal state and then
returns the processed result to 'standard out'.
My problem is that, becuase of the way I have constructed the programme
'standard out' lags behind by one character.
I'm hoping that someone might have a better design they could share with
me.
Tom.
------_=_NextPart_001_01C19CEB.8D51A3F0
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 =
5.5.2653.12">
<TITLE>RE: Help using a state monad</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2>your pattern match</FONT>
<BR><FONT SIZE=3D2>of (s:sx) seems to be the cause of the delay</FONT>
</P>
<P><FONT SIZE=3D2>try</FONT>
</P>
<BR>
<P><FONT SIZE=3D2>--Process the input</FONT>
<BR><FONT SIZE=3D2>mProcess :: String -> State String</FONT>
<BR><FONT SIZE=3D2>mProcess sx =3D do b <- =
isOn</FONT>
<BR><FONT =
SIZE=3D2> &nb=
sp; if ( head sx =
=3D=3D 't' )</FONT>
<BR><FONT =
SIZE=3D2> &nb=
sp; &nb=
sp; then toggle</FONT>
<BR><FONT =
SIZE=3D2> &nb=
sp; &nb=
sp; else return ()</FONT>
<BR><FONT =
SIZE=3D2> &nb=
sp; appOut =
(tuUpper b (head sx)) (mProcess (tail sx))</FONT>
</P>
<P><FONT SIZE=3D2>instead</FONT>
</P>
<P><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: Tom Bevan [<A =
HREF=3D"mailto:tom@regex.com.au">mailto:tom@regex.com.au</A>]</FONT>
<BR><FONT SIZE=3D2>Sent: 14 January 2002 05:58</FONT>
<BR><FONT SIZE=3D2>To: Haskell Cafe List</FONT>
<BR><FONT SIZE=3D2>Subject: Help using a state monad</FONT>
</P>
<BR>
<P><FONT SIZE=3D2>Hi all,</FONT>
</P>
<P><FONT SIZE=3D2>I'm trying to get a feel for how monads might be used =
in a Haskell</FONT>
<BR><FONT SIZE=3D2>program and develop an approach that would be useful =
for larger </FONT>
<BR><FONT SIZE=3D2>projects.</FONT>
<BR><FONT SIZE=3D2>I have tried to model in miniture a programme which =
takes input from</FONT>
<BR><FONT SIZE=3D2>'standard in' and processes it against an internal =
state and then</FONT>
<BR><FONT SIZE=3D2>returns the processed result to 'standard =
out'.</FONT>
<BR><FONT SIZE=3D2>My problem is that, becuase of the way I have =
constructed the programme</FONT>
<BR><FONT SIZE=3D2>'standard out' lags behind by one character.</FONT>
<BR><FONT SIZE=3D2>I'm hoping that someone might have a better design =
they could share with</FONT>
<BR><FONT SIZE=3D2>me.</FONT>
</P>
<P><FONT SIZE=3D2>Tom.</FONT>
</P>
<BR>
<BR>
</BODY>
</HTML>
------_=_NextPart_001_01C19CEB.8D51A3F0--