Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 239
Jack Avatar asked Jun 14 '10 13:06

Jack


1 Answers

You can simply write ().

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

like image 197
tonio Avatar answered Sep 19 '22 14:09

tonio