Advertisement
Guest User

Untitled

a guest
Nov 10th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.91 KB | None | 0 0
  1.   type FieldSelector =
  2.     | FactIndex of int
  3.     | Sum of FieldSelector * FieldSelector
  4.     | ProdLeft of FieldSelector
  5.     | ProdRight of FieldSelector
  6.     | Rec
  7.  
  8.   type Fact = int[]
  9.  
  10.   type TokenElement =
  11.     | TEFact of Fact
  12.     | TELeft of TokenElement
  13.     | TERight of TokenElement
  14.     | TEProd of TokenElement * TokenElement
  15.  
  16.   let lookupTE (fieldSelector:FieldSelector) (tokenElement:TokenElement) =
  17.     let rec loop lsel te =
  18.       match lsel, te with
  19.       | FactIndex index, TEFact ar -> ar.[index]
  20.       | Sum(fl, _), TELeft tel -> loop fl tel
  21.       | Sum(_, fr), TERight ter -> loop fr ter
  22.       | ProdLeft fs, TEProd(teFst,_) -> loop fs teFst
  23.       | ProdRight fs, TEProd(_,teSnd) -> loop fs teSnd
  24.       | Rec, te -> loop fieldSelector te
  25.     loop fieldSelector tokenElement
  26.  
  27.   let listTE = TELeft <| TEFact [|1; 2|]
  28.   let listTE2 = TERight <| TEProd(TEFact [|1; 2|],TELeft <| TEFact [|2; 3|])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement