testing keyboard input for a digit

Jean Saint-Remy <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
Hi,

I am trying to test user's input to see if it contains a digit, but it is not going so well

let rec kbd () = 

  let ls = [0;1;2;3;4;5;6;7;8;9;] (* there doesn't seem to be a way of expressing a range 0..9 *)
  let rec find test = function
    | [] -> raise Not_found
    | hd :: tl -> if test hd then hd else find test tl in 

       print_string "Please enter an item number: ";
       try
          let item = read_line () in 

          if (item = find ls) then failwith "an item should contain a digit ";
          item
     with Failure msg -> (print_endline (msg ^ ", try again"); kbd ()) ;;

-: Error This expr "ls" has type int list but an expression was expected of type 'a -> bool

Thank you for any suggestion

jean
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.