Pregunta

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.

¿Fue útil?

Solución

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
...

Otros consejos

Note that you can write

let x = ... in
  let _ = Hashtbl.iter in ...
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top