Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: A basic misunderstanding of how to program with IO
(Ozgur Akgun)
2. RE: A basic misunderstanding of how to program with IO
(Ken Overton)
----------------------------------------------------------------------
Message: 1
Date: Sat, 8 May 2010 17:09:53 +0100
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] A basic misunderstanding of how to
program with IO
To: Ken Overton <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
I might have misunderstood you, but what about using the existing interact
function:
http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Prelude.html#v:interact
And for your interact, since it is not in the IO monad, you cannot write
such a function. [ don't tell him about the unsafePerformIO :) ]
I am sure you'll get better answers.
Best,
On 8 May 2010 16:55, Ken Overton <[email protected]> wrote:
> Sorry for such a beginner-y question, but is there a way to make a function
> like:
>
> interact :: String -> Resp
> interact txt =
> putStrLn txt
> rsp <- getLine
> return parseResp rsp
>
> parseResp :: String -> Resp
>
> Or is that simply a wrong way of programming in Haskell with IO?
>
> Thanks (and apologies),
>
> -- kov_______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100508/4b6fd4c9/attachment-0001.html
------------------------------
Message: 2
Date: Sat, 8 May 2010 12:20:12 -0400
From: Ken Overton <[email protected]>
Subject: RE: [Haskell-beginners] A basic misunderstanding of how to
program with IO
To: Ozgur Akgun <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Thanks; I guess my 'problem' is that I naturally gravitate to a function that
returns *the result of the interaction* rather than IO, but that seems
impossible anywhere IO is used.
So looking at the 'real' interact function, I guess the Haskell way is to pass
in my function that acts on the data that was read. I guess that makes sense
as then I can separate all my 'action' code from IO code. Is that a reasonable
understanding?
Sorry if this was so obvious; is this kind of pattern documented in greater
detail somewhere? I haven't noticed anything yet, but maybe I've been hoogling
the wrong names.
--kov
________________________________________
From: Ozgur Akgun [[email protected]]
Sent: Saturday, May 08, 2010 12:09 PM
To: Ken Overton
Cc: [email protected]
Subject: Re: [Haskell-beginners] A basic misunderstanding of how to program
with IO
I might have misunderstood you, but what about using the existing interact
function:
http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Prelude.html#v:interact
And for your interact, since it is not in the IO monad, you cannot write such a
function. [ don't tell him about the unsafePerformIO :) ]
I am sure you'll get better answers.
Best,
On 8 May 2010 16:55, Ken Overton
<[email protected]<mailto:[email protected]>> wrote:
Sorry for such a beginner-y question, but is there a way to make a function
like:
interact :: String -> Resp
interact txt =
putStrLn txt
rsp <- getLine
return parseResp rsp
parseResp :: String -> Resp
Or is that simply a wrong way of programming in Haskell with IO?
Thanks (and apologies),
-- kov_______________________________________________
Beginners mailing list
[email protected]<mailto:[email protected]>
http://www.haskell.org/mailman/listinfo/beginners
--
Ozgur Akgun
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 23, Issue 10
*****************************************