Send Beginners mailing list submissions to beginners@haskell.org 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 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. Re: a problem with maps (Dennis Raddle) 2. Re: a problem with maps (Ertugrul Soeylemez) 3. Repeat function application x times? (Christopher Howard) 4. Re: Repeat function application x times? (Magnus Therning) 5. Re: Repeat function application x times? (Ertugrul Soeylemez) 6. Re: Repeat function application x times? (Felipe Almeida Lessa) ---------------------------------------------------------------------- Message: 1 Date: Fri, 22 Jul 2011 20:38:25 -0700 From: Dennis Raddle <dennis.rad...@gmail.com> Subject: Re: [Haskell-beginners] a problem with maps To: beginners@haskell.org Message-ID: <CAKxLvop7=l5euy4dd-jfa7vvr45vmy7nsa8vyzytre79hvy...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Another problem is have is to filter entries in a map. If I have a map Ord k => Map k [a] (essentially, which combines data with the same key into a list) and I have a predicte (k,a) -> Bool (which takes the key and one element in its list and checks it) and I need to regenerate the map, what would be a good way to do that? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110722/5e074878/attachment-0001.htm> ------------------------------ Message: 2 Date: Sat, 23 Jul 2011 05:51:56 +0200 From: Ertugrul Soeylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] a problem with maps To: beginners@haskell.org Message-ID: <20110723055156.16261...@angst.streitmacht.eu> Content-Type: text/plain; charset=US-ASCII Dennis Raddle <dennis.rad...@gmail.com> wrote: > Another problem is have is to filter entries in a map. If I have a map > > Ord k => Map k [a] > > (essentially, which combines data with the same key into a list) > > and I have a predicte (k,a) -> Bool > > (which takes the key and one element in its list and checks it) > > and I need to regenerate the map, what would be a good way to do that? See the foldWithKey function in Data.Map. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ ------------------------------ Message: 3 Date: Fri, 22 Jul 2011 22:11:39 -0800 From: Christopher Howard <christopher.how...@frigidcode.com> Subject: [Haskell-beginners] Repeat function application x times? To: Haskell Beginners <beginners@haskell.org> Message-ID: <4e2a661b.9030...@frigidcode.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Is there a convenient stock function in prelude/base that applies a function to a single value x number of times and returns the result? (I.e., does not return a list, but the final value.) Something like applyN :: Integral b => (a -> a) -> b -> a -> a Honestly I looked through the base hierarchy and at hoogle but I am missing it. -- frigidcode.com theologia.indicium.us ------------------------------ Message: 4 Date: Sat, 23 Jul 2011 08:26:05 +0200 From: Magnus Therning <mag...@therning.org> Subject: Re: [Haskell-beginners] Repeat function application x times? To: beginners@haskell.org Message-ID: <20110723062605.GA4386@ohann> Content-Type: text/plain; charset="us-ascii" On Fri, Jul 22, 2011 at 10:11:39PM -0800, Christopher Howard wrote: > Is there a convenient stock function in prelude/base that applies a > function to a single value x number of times and returns the result? > (I.e., does not return a list, but the final value.) Something like > > applyN :: Integral b => (a -> a) -> b -> a -> a > > Honestly I looked through the base hierarchy and at hoogle but I am > missing it. I'm not sure there is one, but it's rather simple to build one out of `iterate` and `!!`. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: mag...@therning.org jabber: mag...@therning.org twitter: magthe http://therning.org/magnus Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. -- Alan Kay -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20110723/c5dec657/attachment-0001.pgp> ------------------------------ Message: 5 Date: Sat, 23 Jul 2011 08:26:33 +0200 From: Ertugrul Soeylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] Repeat function application x times? To: beginners@haskell.org Message-ID: <20110723082633.4a7f7...@angst.streitmacht.eu> Content-Type: text/plain; charset=US-ASCII Christopher Howard <christopher.how...@frigidcode.com> wrote: > Is there a convenient stock function in prelude/base that applies a > function to a single value x number of times and returns the result? > (I.e., does not return a list, but the final value.) Something like > > applyN :: Integral b => (a -> a) -> b -> a -> a > > Honestly I looked through the base hierarchy and at hoogle but I am > missing it. No, but it's easy to define: applyN :: Int -> (a -> a) -> a -> a applyN n = foldl (.) id . replicate n Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ ------------------------------ Message: 6 Date: Sat, 23 Jul 2011 03:28:42 -0300 From: Felipe Almeida Lessa <felipe.le...@gmail.com> Subject: Re: [Haskell-beginners] Repeat function application x times? To: Christopher Howard <christopher.how...@frigidcode.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <CANd=OGGxRveasjEoQSf=7d1f+iflgz1sh_wva0vzkqd9kcp...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 It's straightforward to define it using iterate: applyN :: (a -> a) -> Int -> a -> a applyN f n x = iterate f x !! n Cheers, -- Felipe. ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 37, Issue 50 *****************************************