src/Pure/net.ML
changeset 1458 fd510875fb71
parent 228 4f43430f226e
child 1460 5a6f2aabd538
--- a/src/Pure/net.ML	Mon Jan 29 13:50:10 1996 +0100
+++ b/src/Pure/net.ML	Mon Jan 29 13:56:41 1996 +0100
@@ -1,6 +1,6 @@
-(*  Title: 	net
+(*  Title:      net
     ID:         $Id$
-    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
+    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     Copyright   1993  University of Cambridge
 
 Discrimination nets: a data structure for indexing items
@@ -46,9 +46,9 @@
 *)
 fun add_key_of_terms (t, cs) = 
   let fun rands (f$t, cs) = CombK :: rands (f, add_key_of_terms(t, cs))
-	| rands (Const(c,_), cs) = AtomK c :: cs
-	| rands (Free(c,_),  cs) = AtomK c :: cs
-	| rands (Bound i,  cs)   = AtomK (string_of_bound i) :: cs
+        | rands (Const(c,_), cs) = AtomK c :: cs
+        | rands (Free(c,_),  cs) = AtomK c :: cs
+        | rands (Bound i,  cs)   = AtomK (string_of_bound i) :: cs
   in case (head_of t) of
       Var _ => VarK :: cs
     | Abs _ => VarK :: cs
@@ -66,9 +66,9 @@
   Lookup functions preserve order in items stored at same level.
 *)
 datatype 'a net = Leaf of 'a list
-		| Net of {comb: 'a net, 
-			  var: 'a net,
-			  alist: (string * 'a net) list};
+                | Net of {comb: 'a net, 
+                          var: 'a net,
+                          alist: (string * 'a net) list};
 
 val empty = Leaf[];
 val emptynet = Net{comb=empty, var=empty, alist=[]};
@@ -76,7 +76,7 @@
 
 (*** Insertion into a discrimination net ***)
 
-exception INSERT;	(*duplicate item in the net*)
+exception INSERT;       (*duplicate item in the net*)
 
 
 (*Adds item x to the list at the node addressed by the keys.
@@ -89,25 +89,25 @@
             if gen_mem eq (x,xs) then  raise INSERT  else Leaf(x::xs)
         | ins1 (keys, Leaf[]) = ins1 (keys, emptynet)   (*expand empty...*)
         | ins1 (CombK :: keys, Net{comb,var,alist}) =
-	    Net{comb=ins1(keys,comb), var=var, alist=alist}
-	| ins1 (VarK :: keys, Net{comb,var,alist}) =
-	    Net{comb=comb, var=ins1(keys,var), alist=alist}
-	| ins1 (AtomK a :: keys, Net{comb,var,alist}) =
-	    let fun newpair net = (a, ins1(keys,net)) 
-		fun inslist [] = [newpair empty]
-		  | inslist((b: string, netb) :: alist) =
-		      if a=b then newpair netb :: alist
-		      else if a<b then (*absent, ins1ert in alist*)
-			  newpair empty :: (b,netb) :: alist
-		      else (*a>b*) (b,netb) :: inslist alist
-	    in  Net{comb=comb, var=var, alist= inslist alist}  end
+            Net{comb=ins1(keys,comb), var=var, alist=alist}
+        | ins1 (VarK :: keys, Net{comb,var,alist}) =
+            Net{comb=comb, var=ins1(keys,var), alist=alist}
+        | ins1 (AtomK a :: keys, Net{comb,var,alist}) =
+            let fun newpair net = (a, ins1(keys,net)) 
+                fun inslist [] = [newpair empty]
+                  | inslist((b: string, netb) :: alist) =
+                      if a=b then newpair netb :: alist
+                      else if a<b then (*absent, ins1ert in alist*)
+                          newpair empty :: (b,netb) :: alist
+                      else (*a>b*) (b,netb) :: inslist alist
+            in  Net{comb=comb, var=var, alist= inslist alist}  end
   in  ins1 (keys,net)  end;
 
 fun insert_term ((t,x), net, eq) = insert((key_of_term t, x), net, eq);
 
 (*** Deletion from a discrimination net ***)
 
-exception DELETE;	(*missing item in the net*)
+exception DELETE;       (*missing item in the net*)
 
 (*Create a new Net node if it would be nonempty*)
 fun newnet {comb=Leaf[], var=Leaf[], alist=[]} = empty
@@ -124,19 +124,19 @@
   let fun del1 ([], Leaf xs) =
             if gen_mem eq (x,xs) then Leaf (gen_rem eq (xs,x))
             else raise DELETE
-	| del1 (keys, Leaf[]) = raise DELETE
-	| del1 (CombK :: keys, Net{comb,var,alist}) =
-	    newnet{comb=del1(keys,comb), var=var, alist=alist}
-	| del1 (VarK :: keys, Net{comb,var,alist}) =
-	    newnet{comb=comb, var=del1(keys,var), alist=alist}
-	| del1 (AtomK a :: keys, Net{comb,var,alist}) =
-	    let fun newpair net = (a, del1(keys,net)) 
-		fun dellist [] = raise DELETE
-		  | dellist((b: string, netb) :: alist) =
-		      if a=b then conspair(newpair netb, alist)
-		      else if a<b then (*absent*) raise DELETE
-		      else (*a>b*)  (b,netb) :: dellist alist
-	    in  newnet{comb=comb, var=var, alist= dellist alist}  end
+        | del1 (keys, Leaf[]) = raise DELETE
+        | del1 (CombK :: keys, Net{comb,var,alist}) =
+            newnet{comb=del1(keys,comb), var=var, alist=alist}
+        | del1 (VarK :: keys, Net{comb,var,alist}) =
+            newnet{comb=comb, var=del1(keys,var), alist=alist}
+        | del1 (AtomK a :: keys, Net{comb,var,alist}) =
+            let fun newpair net = (a, del1(keys,net)) 
+                fun dellist [] = raise DELETE
+                  | dellist((b: string, netb) :: alist) =
+                      if a=b then conspair(newpair netb, alist)
+                      else if a<b then (*absent*) raise DELETE
+                      else (*a>b*)  (b,netb) :: dellist alist
+            in  newnet{comb=comb, var=var, alist= dellist alist}  end
   in  del1 (keys,net)  end;
 
 fun delete_term ((t,x), net, eq) = delete((key_of_term t, x), net, eq);
@@ -154,7 +154,7 @@
 
 (*Return the list of items at the given node, [] if no such node*)
 fun lookup (Leaf(xs), []) = xs
-  | lookup (Leaf _, _::_) = []	(*non-empty keys and empty net*)
+  | lookup (Leaf _, _::_) = []  (*non-empty keys and empty net*)
   | lookup (Net{comb,var,alist}, CombK :: keys) = lookup(comb,keys)
   | lookup (Net{comb,var,alist}, VarK :: keys) = lookup(var,keys)
   | lookup (Net{comb,var,alist}, AtomK a :: keys) = 
@@ -166,7 +166,7 @@
   | net_skip (Net{comb,var,alist}, nets) = 
     foldr net_skip 
           (net_skip (comb,[]), 
-	   foldr (fn ((_,net), nets) => net::nets) (alist, var::nets));
+           foldr (fn ((_,net), nets) => net::nets) (alist, var::nets));
 
 (** Matching and Unification**)
 
@@ -182,25 +182,25 @@
 *)
 fun matching unif t (net,nets) =
   let fun rands _ (Leaf _, nets) = nets
-	| rands t (Net{comb,alist,...}, nets) =
-	    case t of 
-		f$t => foldr (matching unif t) (rands f (comb,[]), nets)
-	      | Const(c,_) => look1 (alist, c) nets
-	      | Free(c,_)  => look1 (alist, c) nets
-	      | Bound i    => look1 (alist, string_of_bound i) nets
-	      | _      	   => nets
+        | rands t (Net{comb,alist,...}, nets) =
+            case t of 
+                f$t => foldr (matching unif t) (rands f (comb,[]), nets)
+              | Const(c,_) => look1 (alist, c) nets
+              | Free(c,_)  => look1 (alist, c) nets
+              | Bound i    => look1 (alist, string_of_bound i) nets
+              | _          => nets
   in 
      case net of
-	 Leaf _ => nets
+         Leaf _ => nets
        | Net{var,...} =>
-	   case (head_of t) of
-	       Var _ => if unif then net_skip (net,nets)
-			else var::nets	   	(*only matches Var in net*)
+           case (head_of t) of
+               Var _ => if unif then net_skip (net,nets)
+                        else var::nets          (*only matches Var in net*)
 (*If "unif" then a var instantiation in the abstraction could allow
   an eta-reduction, so regard the abstraction as a wildcard.*)
-	     | Abs _ => if unif then net_skip (net,nets)
-			else var::nets		(*only a Var can match*)
-	     | _ => rands t (net, var::nets)	(*var could match also*)
+             | Abs _ => if unif then net_skip (net,nets)
+                        else var::nets          (*only a Var can match*)
+             | _ => rands t (net, var::nets)    (*var could match also*)
   end;
 
 val extract_leaves = flat o map (fn Leaf(xs) => xs);