| [] -> [ap]
| head :: tail when fst head = fst ap -> ap :: tail
| head :: tail -> head :: add_assoc ap tail
+
+(* int of string ************************************************************)
+
+type t = End
+ | Space
+ | Figure of int
+ | Error
+
+let int_of_string s =
+ let l = String.length s in
+ let get_t i =
+ if i = l then End else
+ match s.[i] with
+ | ' ' | '\t' | '\r' | 'n' -> Space
+ | '0' .. '9' -> Figure (Char.code s.[i] - Char.code '0')
+ | _ -> Error
+ in
+ let rec aux i xv = match get_t i, xv with
+ | Error, _
+ | End, None -> raise (Failure "int_of_string")
+ | End, Some v -> v
+ | Space, xv -> aux (succ i) xv
+ | Figure f, None -> aux (succ i) (Some f)
+ | Figure f, Some v -> aux (succ i) (Some (10 * v + f))
+ in
+ aux 0 None