caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Warning 20: Unused function argument
@ 2013-03-22  9:02 Francois Berenger
  2013-03-22  9:05 ` Gabriel Scherer
  2013-03-22 10:18 ` Jacques Garrigue
  0 siblings, 2 replies; 8+ messages in thread
From: Francois Berenger @ 2013-03-22  9:02 UTC (permalink / raw)
  To: caml-list

Hello,

I understand it is turned off by default.

I am a bit surprised as it is as important
to me as an unused variable, which triggers a warning
by default.

Regards,
F.

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

* Re: [Caml-list] Warning 20: Unused function argument
  2013-03-22  9:02 [Caml-list] Warning 20: Unused function argument Francois Berenger
@ 2013-03-22  9:05 ` Gabriel Scherer
  2013-03-22  9:14   ` rixed
  2013-03-22  9:16   ` Francois Berenger
  2013-03-22 10:18 ` Jacques Garrigue
  1 sibling, 2 replies; 8+ messages in thread
From: Gabriel Scherer @ 2013-03-22  9:05 UTC (permalink / raw)
  To: Francois Berenger; +Cc: caml-list

My own guess (pure speculation) as to why this difference is that
enabling it by default would have raised too many warnings on existing
code, in particular breaking code of people sadly using a "all enabled
warnings are errors" discipline (don't!), while unused let-bound
variables where much less frequent in existing code.

On Fri, Mar 22, 2013 at 10:02 AM, Francois Berenger <berenger@riken.jp> wrote:
> Hello,
>
> I understand it is turned off by default.
>
> I am a bit surprised as it is as important
> to me as an unused variable, which triggers a warning
> by default.
>
> Regards,
> F.
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

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

* Re: [Caml-list] Warning 20: Unused function argument
  2013-03-22  9:05 ` Gabriel Scherer
@ 2013-03-22  9:14   ` rixed
  2013-03-22  9:16   ` Francois Berenger
  1 sibling, 0 replies; 8+ messages in thread
From: rixed @ 2013-03-22  9:14 UTC (permalink / raw)
  To: caml-list

> My own guess (pure speculation) as to why this difference is that
> enabling it by default would have raised too many warnings on existing
> code, in particular breaking code of people sadly using a "all enabled
> warnings are errors" discipline (don't!), while unused let-bound
> variables where much less frequent in existing code.

Users are explicitely warned against -warn-error in the manpage for this
very reason. A solution to this problem would be to disable -warn-error
for new flags? Or even better yet, to disable it entirely and deprecate
it, since in all compilers -warn-error is a pain for everyone.


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

* Re: [Caml-list] Warning 20: Unused function argument
  2013-03-22  9:05 ` Gabriel Scherer
  2013-03-22  9:14   ` rixed
@ 2013-03-22  9:16   ` Francois Berenger
  2013-03-22  9:39     ` Gabriel Scherer
  1 sibling, 1 reply; 8+ messages in thread
From: Francois Berenger @ 2013-03-22  9:16 UTC (permalink / raw)
  To: caml-list

On 03/22/2013 06:05 PM, Gabriel Scherer wrote:
> My own guess (pure speculation) as to why this difference is that
> enabling it by default would have raised too many warnings on existing
> code, in particular breaking code of people sadly using a "all enabled
> warnings are errors" discipline (don't!), while unused let-bound
> variables where much less frequent in existing code.

OCaml is not lazy, so that's not very smart if some of my functions
have unused arguments... I have to fix my code. :(

> On Fri, Mar 22, 2013 at 10:02 AM, Francois Berenger <berenger@riken.jp> wrote:
>> Hello,
>>
>> I understand it is turned off by default.
>>
>> I am a bit surprised as it is as important
>> to me as an unused variable, which triggers a warning
>> by default.
>>
>> Regards,
>> F.
>>
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


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

* Re: [Caml-list] Warning 20: Unused function argument
  2013-03-22  9:16   ` Francois Berenger
@ 2013-03-22  9:39     ` Gabriel Scherer
  0 siblings, 0 replies; 8+ messages in thread
From: Gabriel Scherer @ 2013-03-22  9:39 UTC (permalink / raw)
  To: Francois Berenger; +Cc: caml-list

My understanding is that the warning is raised when applying an
argument to an expression whose type is a polymorphic variable (which
will become a function type through type instantiation, but it does
come from a syntactic of the form "let exp foo bar").

This can quite commonly happen if you use the following pattern to
mark not-yet-implemented functions

  let func _ = failwith "TODO"
  ...
  let foo bar = func bar (1 + bar)

Calling a toplevel with option "-w +20":

  # let test _ = failwith "TODO";;
  val test : 'a -> 'b = <fun>
  # test (1 + 2) (3 + 4);;
  Warning 20: this argument will not be used by the function.
  Exception: Failure "TODO".

The warning goes away if you write "test" with the expected number of
arguments (let test x y = failwith "TODO").

As of today, this warning will not get raised if you simply add unused
arguments to your function declaration (and do pass them at the call
site).

On Fri, Mar 22, 2013 at 10:16 AM, Francois Berenger <berenger@riken.jp> wrote:
> On 03/22/2013 06:05 PM, Gabriel Scherer wrote:
>>
>> My own guess (pure speculation) as to why this difference is that
>> enabling it by default would have raised too many warnings on existing
>> code, in particular breaking code of people sadly using a "all enabled
>> warnings are errors" discipline (don't!), while unused let-bound
>> variables where much less frequent in existing code.
>
>
> OCaml is not lazy, so that's not very smart if some of my functions
> have unused arguments... I have to fix my code. :(
>
>
>> On Fri, Mar 22, 2013 at 10:02 AM, Francois Berenger <berenger@riken.jp>
>> wrote:
>>>
>>> Hello,
>>>
>>> I understand it is turned off by default.
>>>
>>> I am a bit surprised as it is as important
>>> to me as an unused variable, which triggers a warning
>>> by default.
>>>
>>> Regards,
>>> F.
>>>
>>> --
>>> Caml-list mailing list.  Subscription management and archives:
>>> https://sympa.inria.fr/sympa/arc/caml-list
>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>>
>>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

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

* Re: [Caml-list] Warning 20: Unused function argument
  2013-03-22  9:02 [Caml-list] Warning 20: Unused function argument Francois Berenger
  2013-03-22  9:05 ` Gabriel Scherer
@ 2013-03-22 10:18 ` Jacques Garrigue
  2013-03-25  4:58   ` Francois Berenger
  1 sibling, 1 reply; 8+ messages in thread
From: Jacques Garrigue @ 2013-03-22 10:18 UTC (permalink / raw)
  To: Francois Berenger; +Cc: caml-list

On 2013/03/22, at 18:02, Francois Berenger <berenger@riken.jp> wrote:

> Hello,
> 
> I understand it is turned off by default.
> 
> I am a bit surprised as it is as important
> to me as an unused variable, which triggers a warning
> by default.

Actually, this whole thread is based on a misunderstanding.
This waning is enabled by default (as you can see with ocaml -help),
but, as Gabriel pointed, it is about arguments passed to functions,
not about formal parameters.

Jacques Garrigue

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

* Re: [Caml-list] Warning 20: Unused function argument
  2013-03-22 10:18 ` Jacques Garrigue
@ 2013-03-25  4:58   ` Francois Berenger
  2013-03-25  6:08     ` Jacques Garrigue
  0 siblings, 1 reply; 8+ messages in thread
From: Francois Berenger @ 2013-03-25  4:58 UTC (permalink / raw)
  To: caml-list

On 03/22/2013 07:18 PM, Jacques Garrigue wrote:
> On 2013/03/22, at 18:02, Francois Berenger <berenger@riken.jp> wrote:
>
>> Hello,
>>
>> I understand it is turned off by default.
>>
>> I am a bit surprised as it is as important
>> to me as an unused variable, which triggers a warning
>> by default.
>
> Actually, this whole thread is based on a misunderstanding.
> This waning is enabled by default (as you can see with ocaml -help),
> but, as Gabriel pointed, it is about arguments passed to functions,
> not about formal parameters.

So, there is no warning about unused formal parameters?

After some large refactoring of some code, I may have some.

If I understand correctly:

# ocaml -w +20
# let test_w20 x y z = x, y;;
val test_w20 : 'a -> 'b -> 'c -> 'a * 'b = <fun>
# test_w20 1 2 3;;
- : int * int = (1, 2)

Produces no warning.

Thanks,
F.


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

* Re: [Caml-list] Warning 20: Unused function argument
  2013-03-25  4:58   ` Francois Berenger
@ 2013-03-25  6:08     ` Jacques Garrigue
  0 siblings, 0 replies; 8+ messages in thread
From: Jacques Garrigue @ 2013-03-25  6:08 UTC (permalink / raw)
  To: Francois Berenger; +Cc: OCaML List Mailing

On 2013/03/25, at 13:58, Francois Berenger <berenger@riken.jp> wrote:

> So, there is no warning about unused formal parameters?
> 
> After some large refactoring of some code, I may have some.
> 
> If I understand correctly:
> 
> # ocaml -w +20
> # let test_w20 x y z = x, y;;
> val test_w20 : 'a -> 'b -> 'c -> 'a * 'b = <fun>
> # test_w20 1 2 3;;
> - : int * int = (1, 2)
> 
> Produces no warning.

You are just using the wrong warning:

$ ocaml -w +27
        OCaml version 4.00.2+dev0-2012-10-03

# let test_w20 x y z = x, y;;
Warning 27: unused variable z.
val test_w20 : 'a -> 'b -> 'c -> 'a * 'b = <fun>

But expect lots of warning in legacy code, as it warns
about _all_ unused variables, including inside
pattern-matching.

	Jacques

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

end of thread, other threads:[~2013-03-25  6:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-22  9:02 [Caml-list] Warning 20: Unused function argument Francois Berenger
2013-03-22  9:05 ` Gabriel Scherer
2013-03-22  9:14   ` rixed
2013-03-22  9:16   ` Francois Berenger
2013-03-22  9:39     ` Gabriel Scherer
2013-03-22 10:18 ` Jacques Garrigue
2013-03-25  4:58   ` Francois Berenger
2013-03-25  6:08     ` Jacques Garrigue

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