[go: up one dir, main page]

  • We can remove an assert_false by putting XPair in the hashtbl:

    type xpair = XPair : (_ * _) ty' -> xpair
    
    let tpair : type a b. a ty' -> b ty' -> (a * b) ty' =
     fun a b ->
      let key = (Xid a.id, Xid b.id) in
      try
        let (XPair r) = Hashtbl.find tpair_table key in
        let TPair (a', b') = r.value in
        match (eq_id a.id a'.id, eq_id b.id b'.id) with
        | Some Eq, Some Eq ->
            r
        | _ ->
            assert false
      with Not_found ->
        let r = {id= gen (); value= TPair (a, b)} in
        Hashtbl.add tpair_table key (XPair r) ;
        r

    The other one is indeed based on the fact that passed parameters are themselves hashcons'ed and I don't think it's possible to enforce this in the type system.

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment