Loading ...
Sorry, an error occurred while loading the content.

Re: "ocaml_beginners"::[] What is the best way to code this data structure?

Expand Messages
  • danbensen@att.net
    ... type x = int type o = string type s = string type xos_list = { o0o: o option; xos: (x*o) list; xfo: x option; s: s } let do_some f = function None - () |
    Message 1 of 12 , Nov 1, 2012
    • 0 Attachment
      > I'm not sure how to figure out if the head of the list is 'x or 'o

      type x = int
      type o = string
      type s = string

      type xos_list = {
      o0o: o option;
      xos: (x*o) list;
      xfo: x option;
      s: s }

      let do_some f = function None -> () | Some x -> f x

      let rec iter do_x do_o { o0o; xos; xfo; _ } =
      do_some do_o o0o; List.iter (fun (x,o) -> do_x x; do_o o) xos;
      do_some do_x xfo

      let () = iter print_int print_string
      { o0o=None; xos = [(1,"o");(2,"oo")]; xfo = Some 3; s="example" }
    Your message has been successfully submitted and would be delivered to recipients shortly.