Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. datatype expression = Constant of int |
  2. Variable of string |
  3. Operator of string * expression |
  4. Pair of expression list |
  5. List of expression list
  6.  
  7. datatype pattern = ConstantP of int
  8. | VariableP of string
  9. | OperatorP of string * pattern
  10. | PairP of pattern list
  11. | ListP of pattern list
  12. | Wildcard
  13.  
  14. (*match (fn : expression * pattern -> (string * expression) list option) -
  15. accepts expression and a pattern. In case of matching returns SOME list of matching in case of not matching it returns NONE.
  16.  
  17. 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.
  18.  
  19. The rules for matching:
  20.  
  21. Wildcard matches all elements and returns empty list of matchings
  22. VariableP s matches with any value of v and returns a list with one binding (s,v)
  23.  
  24. ConstantP 42 matches only with Constant 42 and returns empty list of bindinds. It works the same for all other numbers.
  25.  
  26.  
  27. PairP [a1, a2] matches with Pair [b1,b2] if a1 and b1 matches and a2 and b2 matches.. It returns list of all matches.
  28.  
  29. ListP ps matches with List xs if all elements matches. Match returns a list of all matches.
  30.  
  31. *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement