Hmm, I should probably show an example of using the parser keyword too...

1
2
3
4
5
6
let rec zip = parser
  | [< 'x; s1 >] -> begin parser
    | [< 'y; s2 >] -> [< '(x,y); zip s1 s2 >]
    | [< >] -> [< >]
    end
  | [< >] -> fun _ -> [< >];;

Gives: val zip : 'a Stream -> 'b Stream -> ('a * 'b) Stream in OCaml.

I don't see anyway to use tuples of streams with the parser keyword, hence the nesting; however, it's quite similar to normal lists, except now they're lazy!

By on 6/17/2006 1:31 AM ()

Hi,

It's important to note that OCaml's "Stream"s aren't Haskell-style lazy lists - they are a form of imperative stream much like .NET IEnumerable values, though with lookahead, and are suitable for some parsing applications. (Avoiding the name clash is one reason why we recently switched the F# names for lazy lsits from Stream to LazyList).

If you're after operations on IEnumerable data streams then take a look at the definitions in the existing IEnumerable module. Ienumerable.unfold is an especially powerful function.

Cheers!

Don

By on 6/17/2006 11:06 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper