cons pattern "xy"::xs

This commit is contained in:
darkf 2013-10-27 01:35:32 -07:00
parent 0e60863bc5
commit 1a449a536e
1 changed files with 6 additions and 0 deletions

View File

@ -275,6 +275,12 @@ patternBindings (StrP _) _ = Nothing
-- cons on strings
patternBindings (ConsP x (ListP [])) (StrV (y:[])) = patternBindings x (StrV [y])
-- "xy":xs pattern
patternBindings (ConsP (StrP xp) xsp) (StrV str) =
let len = length xp in
if take len str == xp then -- matches
patternBindings xsp $ StrV (drop len str) -- match the rest of the string
else Nothing -- no match
patternBindings (ConsP xp xsp) (StrV (x:xs)) =
do
xe <- patternBindings xp (StrV [x])