views:

58

answers:

1

Hello, just a fast hint: I want to print a list of strings and I was going to do it by 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

Thanks in advance

+5  A: 

You can simply write ().

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

tonio
Ok, just searched for it and got it! Sorry for this dumb/simple question but haven't found the () empty unit until now :/
Jack
@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