From 1a449a536e2952e551cd77a8c2077fce9220b36c Mon Sep 17 00:00:00 2001 From: darkf Date: Sun, 27 Oct 2013 01:35:32 -0700 Subject: [PATCH] cons pattern "xy"::xs --- interp.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interp.hs b/interp.hs index 07ccb44..8c20b74 100644 --- a/interp.hs +++ b/interp.hs @@ -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])