anchor.diff:  ﻿module BottomUpPriorityParser
  +(*
  +    The BottomUpPriorityParser is responsible for prioritizing a list of expressions into possibly shorter lists of expressions and eliminating ambigious expressions.
  +*)
  +
  +
  +(*
  +    A node consists of 4 attributes: it's Element, a flag if this Node has been collapsed yet and a Left and Right children.
  +
  +    The Collapsed Flag will make sure that a Node does not get collapsed twice.
  +*)
   
   [<CustomEquality; CustomComparison>]
   type Node<'a when 'a : equality and 'a : comparison> = 
  
positive.code:           | :? Node<'a> as y -> compare x.Element y.Element
            | _ -> invalidArg "yobj" "cannot compare values of different types"
  
  
  let prioritize (l:List<'a>) ariety priority merge =
    match l with
    | [] -> failwith "Cannot prioritize empty list"
  
negative.code:       match this.Right with
        | None -> failwith "Cannot lookup right element"
        | Some x -> x
      (*
          The collapse function will make sure that every element has the same amount of left and right arguments as its ariety given the left ariety and right arity.
          The function will return the merged expression, merging is done by the given function f.
          This is done by iterating over every left and right element and assigning those elements to the either left or right element.
          The iterations are stopped once the amount of elements assigned to this Node is equal to its ariety.
  
          It is important to note that this function will give an error if it is not possible to satisfy this expression's ariety.
          If the operator '+' has a left and right ariety of 1 then the expression '+ 2' will not be valid because it's left ariety is not satisfied.
      *)
      member this.Collapse (leftCount:int) (rightCount:int) f =
        let mutable left = []
        if leftCount > 0 then
  