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:  Exercise of "Programming with Arrows" (Kim-Ee Yeoh)
   2. Re:  Exercise of "Programming with Arrows" (Thiago Negri)
   3. Re:  monads do not fit together? (Kees Bleijenberg)


----------------------------------------------------------------------

Message: 1
Date: Mon, 14 Oct 2013 22:42:51 +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] Exercise of "Programming with Arrows"
Message-ID:
        <CAPY+ZdSafPAJ_PKumcFNbUb=tyu7mzg07yam8z+d9jp7_-1...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Tue, Oct 8, 2013 at 10:43 PM, Thiago Negri <[email protected]> wrote:

> data Queue a = Queue [a]
>
> empty :: Queue a
> empty = Queue []
>
> push :: a -> Queue a -> Queue a
> push a (Queue as) = Queue (a:as)
>
> pop :: Queue a -> Maybe (a, Queue a)
> pop (Queue []) = Nothing
> pop (Queue (a:as)) = Just (a, Queue as)
>

This is not a queue!

This is a stack, a Last In First Out structure.

Queues are First In First Out.

Here, I'll help you with the quickcheck instance:

instance (CoArbitrary a, Arbitrary b) => Arbitrary (SP a b)  where
   arbitrary = oneof [liftM2 Put arbitrary arbitrary, liftM Get arbitrary]

Also, we need a dummy show:

instance (Show a, Show b) => Show (SP a b)  where
   show _ = error "SP a b: no show"

The test you need to write is the following:

prop_SP_first :: SP Int Int -> [(Int,Int)] -> Bool
prop_SP_first f xs = x1 == x2  where
   -- your name is thiago and you WILL be cool once you've fixed your buggy
code


-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131014/905359fc/attachment-0001.html>

------------------------------

Message: 2
Date: Mon, 14 Oct 2013 13:06:34 -0300
From: Thiago Negri <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Exercise of "Programming with Arrows"
Message-ID:
        <CABLneZv65P=XsV==iiDbiEJNc86ErUufyWR7TaQ6Q=wq9+x...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks for the new reply.

I've fixed the "queue" not being a real queue (see the last gist I've sent
to the list [1]).

The problem I was having in defining "first" was in my understanding of the
execution of the arrow.
I didn't realize that (>>>) is just the composition function from Category
class.
I tought that only the last output would be received by the second arrow of
(>>>), and it would continue the stream processing from there.
I was really lost.
Now I see that the correct thing to do is to fit a no-op on the second
stream because outputs will be delivered in pairs to the composed arrow.
Sort of a BalanceLine/Merge that I've learned in my COBOL years.
I will run your test cases as soon as I get home.

By the way, I couldn't figure out a way to define an ArrowLoop instance
that "runSP (loop (arr swap))) [1..10]" doesn't evaluate to bottom (loops
forever).
I don't have much time to this, but I'm trying to solve it mentally when I
feel in the mood and typing some code on a 30-min/day basis.
The hackage package that defines a Stream Processor as explained by Hughes
uses a different definition for SP data type and has the same problem when
evaluating "swap" in a loop (it throws an error) [2].
I guess this problem is harder than Hughes expected, as I find it more
difficult to solve than the tricky "first" definition.
Or, I may be missing something huge.
(I still want to solve it by myself, but tips are welcome.)

Thanks,
Thiago.

[1] https://gist.github.com/thiago-negri/2e541a9f9762c727bdd4
[2] http://hackage.haskell.org/package/streamproc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131014/0ff4ce5b/attachment-0001.html>

------------------------------

Message: 3
Date: Tue, 15 Oct 2013 11:00:04 +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: <000601cec984$f09f7090$d1de51b0$@[email protected]>
Content-Type: text/plain; charset="utf-8"

Brandon,

 

Thanks you for your advice.

I want to add CGI support to  a program that writes to a file, but has no 
network access. The old code uses a WriterT with IO in it. Adding another monad 
to the stack with IO to the network, is a bit too difficult for a beginner like 
me.

The old code returns IO [String] ([String] = list of status messages). It is a 
bit annoying that I have to adapt the old code. I just want to grab the status 
messages and convert them to html and write them to the network. 

I wonder, do you always have to create a monadtransformer if your program uses 
2 kinds of IO?

 

Kees 

 

 

Van: Beginners [mailto:[email protected]] Namens Brandon Allbery
Verzonden: maandag 14 oktober 2013 17:03
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 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/20131015/ec944256/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 64, Issue 24
*****************************************

Reply via email to