cons pattern "xy"::xs
This commit is contained in:
parent
0e60863bc5
commit
1a449a536e
|
@ -275,6 +275,12 @@ patternBindings (StrP _) _ = Nothing
|
||||||
|
|
||||||
-- cons on strings
|
-- cons on strings
|
||||||
patternBindings (ConsP x (ListP [])) (StrV (y:[])) = patternBindings x (StrV [y])
|
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)) =
|
patternBindings (ConsP xp xsp) (StrV (x:xs)) =
|
||||||
do
|
do
|
||||||
xe <- patternBindings xp (StrV [x])
|
xe <- patternBindings xp (StrV [x])
|
||||||
|
|
Loading…
Reference in New Issue