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: monads do not fit together? (Kim-Ee Yeoh)
2. Re: monads do not fit together? (Kees Bleijenberg)
3. Re: monads do not fit together? (Brandon Allbery)
4. Re: Exercise of "Programming with Arrows" (Kim-Ee Yeoh)
----------------------------------------------------------------------
Message: 1
Date: Mon, 14 Oct 2013 19:57:49 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] monads do not fit together?
Message-ID:
<capy+zdrqkeamajufjpqh3kemj-h-2vrdc5uy-ga7hwmlpyp...@mail.gmail.com>
Content-Type: text/plain; charset="windows-1252"
On Mon, Oct 14, 2013 at 6:51 PM, Kees Bleijenberg <
[email protected]> wrote:
> The error at the problem line is: parse error on input `<-' ****
>
> If I move the line above the ?if? I get: Couldn't match expected type
> `CGIT IO t0' with actual type `IO [String]'. ****
>
Looks like you're missing a "do". You're writing code like this:
if blah then
x <- foo
bar x
else
quux
when you need to write
if blah then do
x <- foo
bar x
else
quux
Recommended exercises:
* can you see in your mind's eye the desugaring of do-syntax?
* how would you write it in a single line, i.e. without using indentation
a.k.a. "layout" -- hint: look up curly braces
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131014/8e94857a/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 14 Oct 2013 16:58:47 +0200
From: "Kees Bleijenberg" <[email protected]>
To: "'The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell'" <[email protected]>
Subject: Re: [Haskell-beginners] monads do not fit together?
Message-ID: <000001cec8ed$e2800c50$a78024f0$@[email protected]>
Content-Type: text/plain; charset="us-ascii"
Kim,
I simplified the problem by removing the if then. After that I desugared the
do block to what I think is the equivalent with >> and >>=.
I get the same message (Couldn't match expected type `CGIT IO a0' with
actual type `IO [String]'). I think I do understand where this message is
coming from. But what can I do to fix it?
Kees
module Main(
main
)
where
import Network.CGI
import Text.XHtml
import Text.XHtml.Transitional
import Data.Maybe
runRefreshFirewall :: String -> IO [String]
runRefreshFirewall un = do
return ["test" ]
inputCgiOkPage :: String -> [String] -> Html
inputCgiOkPage un msgs = body << h1 << ("Un: " ++ un)
{--
cgiMain :: CGI CGIResult
cgiMain = do
maybeUn <- getInput "un"
do
msgs <-runRefreshFirewall (fromJust maybeUn)
output $ renderHtml $ (inputCgiOkPage (fromJust maybeUn) msgs)
--}
cgiMain :: CGI CGIResult
cgiMain = (getInput "un") >>= \maybeUn -> (runRefreshFirewall (fromJust
maybeUn) >>=
\msgs -> (output $ renderHtml $ inputCgiOkPage
(fromJust maybeUn) msgs))
main :: IO ()
main = runCGI $ handleErrors cgiMain
Van: Beginners [mailto:[email protected]] Namens Kim-Ee Yeoh
Verzonden: maandag 14 oktober 2013 14:58
Aan: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell
Onderwerp: Re: [Haskell-beginners] monads do not fit together?
On Mon, Oct 14, 2013 at 6:51 PM, Kees Bleijenberg
<[email protected]> wrote:
The error at the problem line is: parse error on input `<-'
If I move the line above the 'if' I get: Couldn't match expected type `CGIT
IO t0' with actual type `IO [String]'.
Looks like you're missing a "do". You're writing code like this:
if blah then
x <- foo
bar x
else
quux
when you need to write
if blah then do
x <- foo
bar x
else
quux
Recommended exercises:
* can you see in your mind's eye the desugaring of do-syntax?
* how would you write it in a single line, i.e. without using indentation
a.k.a. "layout" -- hint: look up curly braces
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131014/a898241c/attachment-0001.html>
------------------------------
Message: 3
Date: Mon, 14 Oct 2013 11:03:01 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] monads do not fit together?
Message-ID:
<cakfcl4w1c6z2zhd0sdchd3qbcsvyr+fdgc+fpobwjpswssc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Mon, Oct 14, 2013 at 10:58 AM, Kees Bleijenberg <
[email protected]> wrote:
> I get the same message (Couldn't match expected type `CGIT IO a0' with
> actual type `IO [String]'). I think I do understand where this message is
> coming from. But what can I do to fix it?
>
For now, you just correct the type of runRefreshFirewall; it should be
runRefreshFirewall :: String -> CGIT IO [String]
If you are intending to run actual IO actions in the real thing, you'll
need to use liftIO to "reach" the IO embedded in the CGIT IO a.
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131014/3adb1f14/attachment-0001.html>
------------------------------
Message: 4
Date: Mon, 14 Oct 2013 22:33:02 +0700
From: Kim-Ee Yeoh <[email protected]>
To: "[email protected]" <[email protected]>
Subject: Re: [Haskell-beginners] Exercise of "Programming with Arrows"
Message-ID:
<CAPY+ZdTFw664L=e5ecmc68pli-r8mwralhfyrds3j-zafex...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Tue, Oct 8, 2013 at 4:08 AM, Thiago Negri <[email protected]> wrote:
> I agree with "no-op assembly line", but when I'm using `first` on a
processor, I want to process the first stream *only*. The second stream
should remain as it was not touched, so future processors will receive the
same sequence from the second stream.
We are in violent agreement!
> I mean, I think I need to guarantee that this definition holds:
>
> `g *** f` is the same as `first g >>> swap >>> first f >>> swap`
Excellent! Let's turn to laws and definitions to be _precise_ in what we're
saying.
> If my implementation of `first` uses a real no-op assembly line for `c`
(i.e., `arr id`), then I would lose the stream.
To that end, consider this easy problem: using
(1) the arrow laws that you know off the top of your head, and
(2) the above definition of (***)
can you show that g *** (arr id) = first g?
Because arr id, as you noted, is a no-op.
Do you see what's going on?
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131014/02f1efcf/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 64, Issue 23
*****************************************