Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] 'should have type unit' warning in 'let _ =' ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] 'should have type unit' warning in 'let _ =' ?

> i had a minor bug where the last expression in a 
> let _ = ...
> block of my module was not fully applied and hence was returning a 
> functional value rather than apply the function (because I had added a 
> parameter to the function).
> pretty harmless, but it led me to wonder why I wasn't writing 'let () = 
> ..' for all my module initialization blocks, which would have given me 
> 'warning should have type unit' in the above situation.
> So is there a reason why the commonly used idiom seems to be 'let _ =' 
> rather than 'let () = '? 

I suppose this is the 1 character difference :-)
Programmers are lazy.
I've been advocating using "let () =" for a while now, and I am of
course using it myself.

By the way, there is a reason "let _ =" produces no warning: this is
the only way to do a partial application without warning.
"expr; ..." and even "ignore (expr); ..." will produce a warning.

By the way, I'm always disabling the s warning ("should be unit"), to
avoid being tempted by using "let _ = expr in " when I want to ignore
the result of a fully applied expression which does not return unit.
I know ignore does it, but I'm lazy too.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: