Skip to content

Instantly share code, notes, and snippets.

@zsol
Created June 2, 2012 21:22
Show Gist options
  • Save zsol/2859994 to your computer and use it in GitHub Desktop.
Save zsol/2859994 to your computer and use it in GitHub Desktop.
subListOf
prefixOf [] _ = True
prefixOf (x:xs) (y:ys) = x == y && xs `prefixOf` ys
prefixOf _ _ = False
subListOf l [] = null l
subListOf l m@(_:ys) = l `prefixOf` m || l `subListOf` ys
--not sure if ghc transforms the above, but here's a tail recursive version
subListOf' l [] = null l
subListOf' l m@(_:ys)
| l `prefixOf` m = True
| otherwise = l `subListOf` ys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment