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!
orderings = map orderingthanks!ordering = map fst . sortBy (compare `on` snd) . zip [0..].oncan be found inData.Function; useful exactly for these situations.