Hello,
`return` is the initial value. So, `replicate x oveKnignt)` is a list of functions. `foldr` folds them with initial value `return` with the `<=<` between them: functions are folding with (<=<). First folding value is `return` function. You can check the types with :t something in the GHCi.
Result of folding is flow of functions or long functions circuit. `return start` is the same as to pass `start` to this functions circuit:
inMany x start = foldr (<=<) return (replicate x oveKnight) $ start
Idea seems, to make from [KnighPos -> [KnighPos]] functions list one function: KnighPos -> [KnighPos] performing those functions step by step (<=<) and to pass `start` to it. Due to `<=<` joining of functions is not "do", but "do for each...", because <=< is in the list monad. Something like:
for x in f-last start:You can look at these types:
for y in f-prelast x:
...
:t foldr
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
:t (<=<)
(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
Dear List,
Chapter 13 of LYAH (http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions) has the following code block
import Data.List
inMany :: Int -> KnightPos -> [KnightPos]
inMany x start = return start >>= foldr (<=<) return (replicate x oveKnight)
What I'd like to know is where the accumulator of foldr is in this example.
Regards,
- Olumide
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners