diff lib/ur/string.ur @ 1272:56bd4a4f6e66

Some serious bug-fix work to get HTML example to compile; this includes fixing a bug with 'val' patterns in Unnest and the need for more local reduction in Especialize
author Adam Chlipala <adamc@hcoop.net>
date Thu, 03 Jun 2010 13:04:37 -0400
parents 9df124fcab3d
children f0afe61a6f8b
line wrap: on
line diff
--- a/lib/ur/string.ur	Tue Jun 01 15:46:24 2010 -0400
+++ b/lib/ur/string.ur	Thu Jun 03 13:04:37 2010 -0400
@@ -11,7 +11,15 @@
 val index = Basis.strindex
 val atFirst = Basis.strchr
 
-fun mindex {Haystack = s, Needle = chs} = Basis.strcspn s chs
+fun mindex {Haystack = s, Needle = chs} =
+    let
+        val n = Basis.strcspn s chs
+    in
+        if n >= length s then
+            None
+        else
+            Some n
+    end
 
 fun substring s {Start = start, Len = len} = Basis.substring s start len