Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Francois Berenger <berenger@riken.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Warning 20: Unused function argument
Date: Fri, 22 Mar 2013 10:39:30 +0100	[thread overview]
Message-ID: <CAPFanBFKBTOx=A_mCRu+1yfu+ZkjMCo4O+foUya=bahuffEynQ@mail.gmail.com> (raw)
In-Reply-To: <514C2172.7090609@riken.jp>

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

  reply	other threads:[~2013-03-22  9:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-22  9:02 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 [this message]
2013-03-22 10:18 ` Jacques Garrigue
2013-03-25  4:58   ` Francois Berenger
2013-03-25  6:08     ` Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPFanBFKBTOx=A_mCRu+1yfu+ZkjMCo4O+foUya=bahuffEynQ@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=berenger@riken.jp \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox