Created
June 2, 2012 21:22
-
-
Save zsol/2859994 to your computer and use it in GitHub Desktop.
subListOf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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