diff lib/ur/list.ur @ 839:b2413e4dd109

List library additions; fix another substructure unification bug
author Adam Chlipala <adamc@hcoop.net>
date Sat, 06 Jun 2009 14:09:30 -0400
parents d07980bf1444
children e4a02e4fa35c
line wrap: on
line diff
--- a/lib/ur/list.ur	Tue Jun 02 19:28:25 2009 -0400
+++ b/lib/ur/list.ur	Sat Jun 06 14:09:30 2009 -0400
@@ -122,3 +122,31 @@
     in
         fold []
     end
+
+fun assoc [a] [b] (_ : eq a) (x : a) =
+    let
+        fun assoc' ls =
+            case ls of
+                [] => None
+              | (y, z) :: ls =>
+                if x = y then
+                    Some z
+                else
+                    assoc' ls
+    in
+        assoc'
+    end
+
+fun search [a] [b] f =
+    let
+        fun search' ls =
+            case ls of
+                [] => None
+              | x :: ls =>
+                case f x of
+                    None => search' ls
+                  | v => v
+    in
+        search'
+    end
+