{-
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.