[Haskell-beginners] Help with "20 intermediate haskell exercises"
Patrick LeBoutillier
patrick.leboutillier at gmail.com
Mon Jul 6 15:55:34 EDT 2009
Hi,
On Sun, Jul 5, 2009 at 3:44 PM, Daniel Fischer<daniel.is.fischer at web.de> wrote:
> Am Sonntag 05 Juli 2009 21:05:20 schrieb Patrick LeBoutillier:
>> Hi,
>>
>> Thanks for the help. I figured it out after that. I'm having a hard
>> time with the other exercises though, I'm currently stuck at 14:
>>
>>
>> class Misty m where
>> banana :: (a -> m b) -> m a -> m b
>> unicorn :: a -> m a
>>
>> -- Exercise 14
>> -- Relative Difficulty: 6
>> moppy :: (Misty m) => [a] -> (a -> m b) -> m [b]
>> moppy = error "todo"
>
> moppy [] mop = ?
> moppy (a:as) mop = (mop a) ?? (moppy as mop)
>
> use (among other things) banana and unicorn to replace the question marks
I came up with this:moppy [] mop = unicorn []
moppy (a:as) mop = banana (\b -> banana (\bs -> unicorn (b:bs)) (moppy
as mop)) (mop a)
moppy [] mop = unicorn []
moppy (a:as) mop = banana (\b -> banana (\bs -> unicorn (b:bs)) (moppy
as mop)) (mop a)
How do I make the second one nicer/shorter?
Patrick
>
>>
>>
>> Does anyone know if the solutions are posted anywhere?
>
> They're (under different names) in the standard libraries :)
I found it: forM
>
>>
>>
>> Patrick
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
More information about the Beginners
mailing list