Trying to implement a function that will return a list of ints the represent an ordering of each list of doubles, e.g.:
orderings [ [1.0, 2.0, 3.0], [3.0, 2.0, 1.0] ]
> [ [0, 1, 2], [2, 1, 0] ]
However, having trouble with my pattern matching for some reason:
import Data.List
-- Return a list of orderings for each list of doubles
orderings:: [[Double]] -> [Int]
orderings [] = []
orderings x:xs = (ordering x):(orderings xs)
ordering:: [Double] -> [Int]
ordering xs = [i | (i, _) <- sorted] where
sorted = sortBy (\(i1, e1) (i2,e2) -> compare e1 e2) $ zip [0..] xs
Error is:
Parse error in pattern: orderings
Can’t see the error for the life of me!
Two more problems (in addition to the missing parentheses around
x:xs):the type of
orderingsis wrong; I suspect it should be[[Double]] -> [[Int]]xis not in scope inordering; I suspect it should bexsHere’s the corrected code: