Frage

I'm a beginner in OCaml, and i have a problem with series of let, like:

let x = myFun y in
let z = myFun x in
...

But, between the lets, i use Hashtbl.iter and other functions that returns unit. If i do:

let x = myFun y in
Hashtbl.iter (...) ...
let z = myFun x in
...

The compiler raises an error. But, if i do:

let x = myFun y in
let h = Hashtbl.iter (...) ...
let z = myFun x in
...

The compiler don't raise any error, just warnings showing that "h" is never used. What's the best way to do that without any problem? Thanks.

War es hilfreich?

Lösung

You have to use ; to separate expressions:

e1 ; e2

This performs the side-effects in e1 and discards the result, and then evaluates `e2.

So in your case:

let x = myFun y in
Hashtbl.iter (...) ... ;
let z = myFun x in
...

Andere Tipps

Note that you can write

let x = ... in
  let _ = Hashtbl.iter in ...
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top