caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Stream parsing - caml light vs. ocaml
@ 1998-06-01  5:22 Norman Davis
  1998-06-01 10:48 ` Toby Moth
  0 siblings, 1 reply; 2+ messages in thread
From: Norman Davis @ 1998-06-01  5:22 UTC (permalink / raw)
  To: caml-list

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Stream parsing - caml light vs. ocaml
  1998-06-01  5:22 Stream parsing - caml light vs. ocaml Norman Davis
@ 1998-06-01 10:48 ` Toby Moth
  0 siblings, 0 replies; 2+ messages in thread
From: Toby Moth @ 1998-06-01 10:48 UTC (permalink / raw)
  To: ndavis; +Cc: caml-list


option 1:
let rec spaces = parser  
    [< '' '|'\t'|'\n'; rest >] -> spaces rest
  | [< >] -> ()

option 2:
let rec spaces = parser  
    [< '' '|'\t'|'\n'; _ = spaces >] -> ()
  | [< >] -> ()

which may be what you were thinking of





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1998-06-01 11:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-01  5:22 Stream parsing - caml light vs. ocaml Norman Davis
1998-06-01 10:48 ` Toby Moth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).