fork download
  1. import Data.List (foldl')
  2.  
  3. type Collection a = [[a]]
  4.  
  5. bestMatch :: (Eq a) => [a] -> Collection a -> Maybe [a]
  6. bestMatch x c = foldl' f Nothing c where
  7. f Nothing y = if (isMatch y) then Just y else Nothing
  8. f jold@(Just old) y = if ((isMatch y) && (length y > length old)) then Just y else jold
  9. isMatch y = take (length y) x == y
  10.  
  11. main = print $ bestMatch [1,2,3,3] [[1],[1,2,3],[1,2],[1,2,3,2],[1,2,3,4]]
  12.  
Success #stdin #stdout 0s 4700KB
stdin
Standard input is empty
stdout
Just [1,2,3]