14

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
perror
  • 7,071
  • 16
  • 58
  • 85
Jack
  • 131,802
  • 30
  • 241
  • 343

1 Answers1

26

You can simply write ().

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

tonio
  • 10,355
  • 2
  • 46
  • 60
  • Ok, just searched for it and got it! Sorry for this dumb/simple question but haven't found the () empty unit until now :/ – Jack Jun 14 '10 at 13:23
  • 1
    @Jack Well, it is not used that often :) If you write in a purely functional style (without side-effects) you never have to use it at all... – Pascal Cuoq Jun 15 '10 at 03:34