[Haskell-beginners] Exercise of "Programming with Arrows"

Kim-Ee Yeoh ky3 at atamo.com
Mon Oct 14 15:42:51 UTC 2013


On Tue, Oct 8, 2013 at 10:43 PM, Thiago Negri <evohunz at gmail.com> 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.html>


More information about the Beginners mailing list