[Haskell-beginners] Hoogle q5.8: write your own findindices

Frerich Raabe raabe at froglogic.com
Mon Jan 15 15:25:58 UTC 2018


On 2018-01-15 16:02, trent shipley wrote:
> My "intuitive" way of doing this is to use recursion. Take the list, Find 
> the first list element. Send the rest of the list back to the function to 
> keep building the list of positions. Until you are out of list, then you 
> halt.

Sounds like a sensible plan to me!

> I have zero intuition on how to do that on a list comprehension, and the 
> tuple pairs you get from zip just makes it harder.

Do you really need to do it using a list comprehension? As far as I can see, 
the only requirement is that you use the 'find' function.

> I don't really want a solution. What I really want to know is whether there 
> is a "find" function I can import, how to import it, and some relevant 
> documentation.

Yes, there is a standard 'find' function in the Data.List module. See here:

   http://hackage.haskell.org/package/base-4.10.1.0/docs/Data-List.html#v:find

It is part of the 'base' package, i.e. you most certainly already have it. 
You can import it by using e.g.

   -- Bring everything in Data.List into scope
   import Data.List

   -- Bring just the 'find' function into scope
   import Data.List (find)

-- 
Frerich Raabe - raabe at froglogic.com
www.froglogic.com - Multi-Platform GUI Testing


More information about the Beginners mailing list