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. Re: Hoogle q5.8: write your own findindices (trent shipley) ---------------------------------------------------------------------- Message: 1 Date: Thu, 18 Jan 2018 07:58:08 +0000 From: trent shipley <trent.ship...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Hoogle q5.8: write your own findindices Message-ID: <caeflybjgz7l_n4ss4s7rh4hcgqydf9pn0jci0nuhbbj30v_...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" {- 8. Redefine the function positions using the function find. -} positions :: Eq a => a -> [a] -> [Int] positions x xs = [i | (x', i) <- zip xs [0..], x == x'] {- Hutton, Graham. Programming in Haskell (Kindle Locations 1640-1642). Cambridge University Press. Kindle Edition. -} find :: Eq a => a -> [(a,b)] -> [b] find k t = [v | (k',v) <- t, k == k'] {- Hutton, Graham. Programming in Haskell (p. 49). Cambridge University Press. Kindle Edition. -} positions' :: Eq a => a -> [a] -> [Int] positions' x xs = find x (zip xs [0..]) ------------------------------------------------------------------- Having read the chapter a week ago, I had forgotten that Hutton had previously defined a function "find" for tuples (see above). After trying a search of the Kindle book the solution was trivial. Trent. > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180118/e2b31403/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 115, Issue 7 *****************************************