Grigory Fateyev
unread,Dec 1, 2014, 7:48:05 AM12/1/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to haskell...@googlegroups.com
Добрый день!
Прохожу курс FP101x и возник затык с монадами, задание такое:
Implement the function foldLeftM :: Monad m => (a -> b -> m a) -> a ->
[b] -> m a that takes an accumulation function a -> b -> m a, and a
seed of type a and left folds a finite, non-partial list of non-bottom
elements of type b into a single result of type m a
Hint: The recursive structure of foldLeftM looks as follows:
foldLeftM f a [] = ... a ...
foldLeftM f a (x:xs) = foldLeftM f (... f ... a ... (>> ...) xs
Я написал:
foldLeftM f a [] = a
foldLeftM f a (x:xs) = foldLeftM f (f a x >>= \r -> return r) xs
но проверочный тест падает:
*Main> foldLeftM (\a b -> putChar b >> return (b : a ++ [b])) [] "haskell" >>= \r -> putStrLn r
<interactive>:4:45:
Couldn't match expected type `[Char]' with actual type `IO [Char]'
In the first argument of `(++)', namely `a'
In the second argument of `(:)', namely `a ++ [b]'
In the first argument of `return', namely `(b : a ++ [b])'
Простите, я новичок в хаскель и не совсем понимаю что пишу :).
Спасибо!
--
Best regards!
gfborn [at] gmail [dot] com