Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Where is the accumulator in the expression foldr (<=<) return (replicate x oveKnight)? -- from LYAH example (Olumide) 2. Re: Where is the accumulator in the expression foldr (<=<) return (replicate x oveKnight)? -- from LYAH example (Ut Primum) 3. Re: Where is the accumulator in the expression foldr (<=<) return (replicate x oveKnight)? -- from LYAH example (Paul) ---------------------------------------------------------------------- Message: 1 Date: Thu, 26 Jul 2018 02:44:55 +0100 From: Olumide <50...@web.de> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] Where is the accumulator in the expression foldr (<=<) return (replicate x oveKnight)? -- from LYAH example Message-ID: <8d3be724-8f53-0bdb-339f-b713140ae...@web.de> Content-Type: text/plain; charset=utf-8; format=flowed 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 ------------------------------ Message: 2 Date: Thu, 26 Jul 2018 08:11:28 +0200 From: Ut Primum <utpri...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Where is the accumulator in the expression foldr (<=<) return (replicate x oveKnight)? -- from LYAH example Message-ID: <canjdmkl+shdsjb6lnufyfki6s06rkbvgcb6b0_ot0wkaer9...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hi, Looking at the structure of the expression, you should have foldr operator accumulator list So in your example the accumulator should be "return" (because it is the second argument) Il gio 26 lug 2018, 03:45 Olumide <50...@web.de> ha scritto: > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180726/f8ed5708/attachment-0001.html> ------------------------------ Message: 3 Date: Thu, 26 Jul 2018 09:14:07 +0300 From: Paul <aqua...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Where is the accumulator in the expression foldr (<=<) return (replicate x oveKnight)? -- from LYAH example Message-ID: <69c4a3db-de78-6fc3-dbc7-2a0efc10a...@gmail.com> Content-Type: text/plain; charset="utf-8"; Format="flowed" 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: for y in f-prelast x: ... You can look at these types: :t foldr foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b :t (<=<) (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c 26.07.2018 04:44, Olumide wrotes: > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180726/829717dd/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 121, Issue 21 ******************************************