how to to do the "noop but return unit" in OCaml

Jack picture Jack · Jun 14, 2010 · Viewed 9.5k times · Source

I want to print a list of strings after going through a pattern matching just to get into this powerful functionality.

How can I express the "do-nothing-but-return-unit" operation ?

What I mean is:

let print_nodes nodes =
  match nodes with
      []     -> (* here i want to noop *)
    | s :: t -> print_string s; print_nodes t

Answer

tonio picture tonio · Jun 14, 2010

You can simply write ().

See Variant values in the manual: () is how you build the unit value.