Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- datatype expression = Constant of int |
- Variable of string |
- Operator of string * expression |
- Pair of expression list |
- List of expression list
- datatype pattern = ConstantP of int
- | VariableP of string
- | OperatorP of string * pattern
- | PairP of pattern list
- | ListP of pattern list
- | Wildcard
- (*match (fn : expression * pattern -> (string * expression) list option) -
- accepts expression and a pattern. In case of matching returns SOME list of matching in case of not matching it returns NONE.
- We can define matching on pair of (expressin * pattern). Pattern and expression can match or not. If they match we create list of matchings of tuples of names and values ((string * expression) list).. the order of matching list doesnt matter.
- The rules for matching:
- Wildcard matches all elements and returns empty list of matchings
- VariableP s matches with any value of v and returns a list with one binding (s,v)
- ConstantP 42 matches only with Constant 42 and returns empty list of bindinds. It works the same for all other numbers.
- PairP [a1, a2] matches with Pair [b1,b2] if a1 and b1 matches and a2 and b2 matches.. It returns list of all matches.
- ListP ps matches with List xs if all elements matches. Match returns a list of all matches.
- *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement