Real World OCaml (beta 2, community edition) by Yaron Minsky Anil Madhavapeddy Jason Hickey

Real World OCaml (beta 2, community edition) by Yaron Minsky Anil Madhavapeddy Jason Hickey

Author:Yaron Minsky, Anil Madhavapeddy, Jason Hickey
Language: eng
Format: epub
Published: 2013-08-16T16:00:00+00:00


OCaml UTop ∗ classes/iter.topscript ∗ all code

Next, we'll define an actual iterator for lists. We can use this to iterate over the contents of our stack.

# class ['a] list_iterator init = object val mutable current : 'a list = init method has_value = current <> [] method get = match current with hd :: tl -> hd | [] -> raise (Invalid_argument "no value") method next = match current with hd :: tl -> current <- tl | [] -> raise (Invalid_argument "no value") end ;;

class ['a] list_iterator : 'a list -> object val mutable current : 'a list method get : 'a method has_value : bool method next : unit end



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.