Browse thread
[Caml-list] 'should have type unit' warning in 'let _ =' ?
-
henridf@l...
- Jacques Garrigue
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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 _ =' ? |
From: henridf@lcavsun1.epfl.ch
> 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.
Jacques
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners