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. All about monads, exercise 4 (Nathan H?sken)
2. Re: All about monads, exercise 4 (Nathan H?sken)
----------------------------------------------------------------------
Message: 1
Date: Sun, 01 May 2011 01:14:21 +0200
From: Nathan H?sken <[email protected]>
Subject: [Haskell-beginners] All about monads, exercise 4
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hey,
I am currently reading "All about monads". Unfortanlty I have only a pdf
without the solutions to the exercises.
in the previous exercises I defined:
data Sheep = Sheep (Maybe Sheep) (Maybe Sheep)
father :: Sheep -> Maybe Sheep
father (Sheep f m) = f
mother :: Sheep -> Maybe Sheep
mother (Sheep f m) = m
parent :: Sheep -> Maybe Sheep
parent s = (mother s) `mplus` (father s)
parentList :: Sheep -> [Sheep]
parentList s = (maybeToList (mother s)) `mplus` (maybeToList (father s))
Now I am supposed to combine "parent" and "parentList" to a function
parent :: MonadPlus m => Sheep -> m Sheep
Problem, my parent function relies on "mother" and "father", and they
give a Maybe monad. So I need:
mother :: MonadPlus m => Sheep -> m Sheep
do I not?
But I have no Idea of how the body of this function would look.
Anyone can give me a hint?
Thanks!
Nathan
but what I really need, is a function
------------------------------
Message: 2
Date: Sun, 01 May 2011 10:55:37 +0200
From: Nathan H?sken <[email protected]>
Subject: Re: [Haskell-beginners] All about monads, exercise 4
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I have a solution, so for anyone interested I now do:
father :: MonadPlus m => Sheep -> m Sheep
father (Sheep Nothing _) = mzero
father (Sheep (Just f) _) = return f
mother :: MonadPlus m => Sheep -> m Sheep
mother (Sheep _ Nothing) = mzero
mother (Sheep _ (Just m)) = return m
On 05/01/2011 01:14 AM, Nathan H?sken wrote:
> Hey,
>
> I am currently reading "All about monads". Unfortanlty I have only a pdf
> without the solutions to the exercises.
>
> in the previous exercises I defined:
>
> data Sheep = Sheep (Maybe Sheep) (Maybe Sheep)
>
> father :: Sheep -> Maybe Sheep
> father (Sheep f m) = f
>
> mother :: Sheep -> Maybe Sheep
> mother (Sheep f m) = m
>
> parent :: Sheep -> Maybe Sheep
> parent s = (mother s) `mplus` (father s)
>
> parentList :: Sheep -> [Sheep]
> parentList s = (maybeToList (mother s)) `mplus` (maybeToList (father s))
>
> Now I am supposed to combine "parent" and "parentList" to a function
> parent :: MonadPlus m => Sheep -> m Sheep
>
> Problem, my parent function relies on "mother" and "father", and they
> give a Maybe monad. So I need:
> mother :: MonadPlus m => Sheep -> m Sheep
>
> do I not?
> But I have no Idea of how the body of this function would look.
>
> Anyone can give me a hint?
> Thanks!
> Nathan
>
> but what I really need, is a function
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 35, Issue 1
****************************************