To: caml-list@inria.fr
From: Norman Davis <ndavis@ti.com>
Subject: Stream parsing - caml light vs. ocaml
Date: Sun, 31 May 1998 22:22:26 -0700
Message-Id: <BMSMTP8966713870a0384552@dpcmail.itg.ti.com>
Hello,
I am reading "Functional programming using Caml Light" by Michel Mauny, chapter
10 on Streams and Parsers. The "spaces" function (used to remove the next
continuous segment of whitespace) shown there is :
# let rec spaces = function
# [< '' '|'\t'|'\n'; spaces _ >] -> ()
#| [< >] -> ();;
I tried converting it to Objective Caml :
# let rec spaces = parser
[< '' '|'\t'|'\n'; spaces >] -> ()
| [< >] -> ();;
val spaces : char Stream.t -> unit = <fun>
# let s = Stream.of_string " ;";;
val s : char Stream.t = <abstr>
# spaces s;;
- : unit = ()
# Stream.next s;;
- : char = ' '
# Stream.next s;;
- : char = ';'
The stream s had two space characters followed by a semicolon.
After "spaces s", I expected "Stream.next s" to return
a semicolon. What is the correct way to write "spaces" so that it removes all
whitespace from the front of the stream, not just a single whitespace
character.
Thanks.
Norman Davis
ndavis@ti.com
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:14 MET