mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-09 19:22:50 -06:00
primitive pattern matching
This commit is contained in:
21
devel/compiler/Match.hs
Normal file
21
devel/compiler/Match.hs
Normal file
@@ -0,0 +1,21 @@
|
||||
module Match where
|
||||
|
||||
import AbsSrc
|
||||
import AbsTgt
|
||||
|
||||
import Env
|
||||
import STM
|
||||
|
||||
match :: [Case] -> Exp -> STM Env Exp
|
||||
match cs v = checks $ map (tryMatch v) cs
|
||||
|
||||
---- return substitution
|
||||
tryMatch :: Exp -> Case -> STM Env Exp
|
||||
tryMatch e (Cas p v) = if fit (e, p) then return v else raise "no fit" where
|
||||
fit (exp,patt) = case (exp,patt) of
|
||||
(ECst c es, PCon d ps) ->
|
||||
c == d &&
|
||||
length es == length ps &&
|
||||
all fit (zip es ps)
|
||||
(_,PVar _) -> True ---- not is exp contains variables
|
||||
|
||||
Reference in New Issue
Block a user