<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2006/02/87492d48b7b7425a57ea516b1a7f2397"
  from="Jonathan Roewen &lt;jonathan.roewen@g...&gt;"
  author="Jonathan Roewen"
  date="2006-02-25T09:15:54"
  subject="[Caml-list] Weird ref behaviour..."
  prev="2006/02/36ea1d88fbdff2d62bf07e1c69839952"
  next="2006/02/35909e63a1ddf0522135e5b5f5be1f6a"
  next-in-thread="2006/02/35909e63a1ddf0522135e5b5f5be1f6a"
  prev-thread="2006/02/58b79c51b309263043849d99234fa5cb"
  next-thread="2006/02/6c745cdabcb81f4abee3ab4848327146"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Weird ref behaviour...">
<msg 
  url="2006/02/87492d48b7b7425a57ea516b1a7f2397"
  from="Jonathan Roewen &lt;jonathan.roewen@g...&gt;"
  author="Jonathan Roewen"
  date="2006-02-25T09:15:54"
  subject="[Caml-list] Weird ref behaviour...">
<msg 
  url="2006/02/35909e63a1ddf0522135e5b5f5be1f6a"
  from="Pierre Etchemaite &lt;petchema@c...&gt;"
  author="Pierre Etchemaite"
  date="2006-02-25T10:22:47"
  subject="Re: [Caml-list] Weird ref behaviour...">
</msg>
</msg>
</thread>

<contents>
Excuse my denseness, but can someone explain the following:

source:


let fold_string l s f = List.fold_left (fun a b -&gt; if a = "" then f b
else a ^ s ^ (f b)) "" l;;

module Expr = struct
   type t = Entity of string
          | Unknown of string
          | Relation of (string * t list)
   let rec to_string = function
   | Entity x -&gt; x
   | Unknown x -&gt; x
   | Relation (_, []) -&gt; ""
   | Relation (n, l) -&gt; Printf.sprintf "%s(%s)" n (fold_string l "," to_string)
  end;;

open Expr;;

let relation n l = Relation (n,l);;
let unknown n = Unknown n;;
let entity n = Entity n;;

let test (a,b) =
    let bindings = ref [] in
    let rec test left right = match left, right with
    | Entity a, Entity b -&gt; a = b
    | Relation (a,x), Relation (b,y) -&gt; a = b &amp;&amp; List.fold_left2 (fun
a b c -&gt; a &amp;&amp; (test b c)) true x y
    | Entity _ as a, Unknown b
    | (Relation _ as a), Unknown b -&gt; begin try
            test a (List.assoc b !bindings)
        with Not_found -&gt; bindings := (b, a) :: !bindings;
Printf.printf "Unified %s to %s\n" b (to_string a); true
      end
    | _ -&gt; false
    in test a b, !bindings

let test_one = relation "Loves" [relation "Dog" [entity "Fred"];
entity "Fred"], relation "Loves" [unknown "x"; unknown "y"];;
let test_two = relation "Loves" [relation "Dog" [entity "Fred"];
entity "Fred"], relation "Loves" [relation "Dog" [unknown "y"];
unknown "y"];;
let test_three = relation "Loves" [relation "Dog" [entity "Fred"];
entity "Fred"], relation "Loves" [unknown "y"; unknown "y"];;

Toplevel session:

# test test_one;;
Unified x to Dog(Fred)
Unified y to Fred
- : bool * (string * Expr.t) list = (true, [])
# test test_three;;
Unified y to Dog(Fred)
- : bool * (string * Expr.t) list = (false, [])

How can the return value have an empty list???? In fact, for
test_three to correctly return false, the list -has to be- non-empty!

Jonathan

</contents>

</message>

