caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] 'should have type unit' warning in 'let _ =' ?
@ 2003-07-15  0:29 henridf
  2003-07-15  1:04 ` Jacques Garrigue
  0 siblings, 1 reply; 5+ messages in thread
From: henridf @ 2003-07-15  0:29 UTC (permalink / raw)
  To: caml-list

hi, 

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 () = '? 

Thanks

Henri


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] 'should have type unit' warning in 'let _ =' ?
  2003-07-15  0:29 [Caml-list] 'should have type unit' warning in 'let _ =' ? henridf
@ 2003-07-15  1:04 ` Jacques Garrigue
  2003-07-15 11:36   ` Richard Jones
  0 siblings, 1 reply; 5+ messages in thread
From: Jacques Garrigue @ 2003-07-15  1:04 UTC (permalink / raw)
  To: henridf; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] 'should have type unit' warning in 'let _ =' ?
  2003-07-15  1:04 ` Jacques Garrigue
@ 2003-07-15 11:36   ` Richard Jones
  2003-07-16  0:10     ` Jacques Garrigue
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Jones @ 2003-07-15 11:36 UTC (permalink / raw)
  Cc: caml-list

On Tue, Jul 15, 2003 at 10:04:36AM +0900, Jacques Garrigue wrote:
> 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.

Interesting ... what's the use of a partial application which is
then ignored?

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you.
 All new technology is irrelevant until it is taken up by the public.

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] 'should have type unit' warning in 'let _ =' ?
  2003-07-15 11:36   ` Richard Jones
@ 2003-07-16  0:10     ` Jacques Garrigue
  2003-07-16  7:11       ` Jean-Christophe Filliatre
  0 siblings, 1 reply; 5+ messages in thread
From: Jacques Garrigue @ 2003-07-16  0:10 UTC (permalink / raw)
  To: rich; +Cc: caml-list

From: Richard Jones <rich@annexia.org>
> On Tue, Jul 15, 2003 at 10:04:36AM +0900, Jacques Garrigue wrote:
> > 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.
> 
> Interesting ... what's the use of a partial application which is
> then ignored?

The same as all application whose result is ignored: side effects.
I know this is quite rare. (I can remember using this only once.)
But it would be disturbing to make it completely impossible.

Or is it not so important?
Actually I wonder whether it would not be safer to simply warn for all
unused partial applications in a compiled program. This is a bit
subtle, as one has to keep track of unused variables too (functions
defined by partial application which are never used).

A middle ground would be to only warn when the wild pattern matches a
function type, assuming that when you name something you know what
you are doing. This would be mostly compatible: you just have to name
the pattern when you want to discard a function. As a nice aside, it
would avoid most uses of "ignore".

By the way, my personal approach would be to let programers declare what
they want: remove the "should be unit" warning (it can be easily
enforced by "let () = ... in"), and remove all warnings on "ignore",
since you could then write "let _ = ... in" if you want the partial
application warning. But this is maybe expecting too much from
programmers.

Comments?

Jacques Garrigue

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] 'should have type unit' warning in 'let _ =' ?
  2003-07-16  0:10     ` Jacques Garrigue
@ 2003-07-16  7:11       ` Jean-Christophe Filliatre
  0 siblings, 0 replies; 5+ messages in thread
From: Jean-Christophe Filliatre @ 2003-07-16  7:11 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: caml-list


Jacques Garrigue writes:
 > A middle ground would be to only warn when the wild pattern matches a
 > function type

That would be great! 

Could it be done before 3.07 is released? :-)

-- 
Jean-Christophe

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-07-16  7:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-15  0:29 [Caml-list] 'should have type unit' warning in 'let _ =' ? henridf
2003-07-15  1:04 ` Jacques Garrigue
2003-07-15 11:36   ` Richard Jones
2003-07-16  0:10     ` Jacques Garrigue
2003-07-16  7:11       ` Jean-Christophe Filliatre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).