caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Krishnaswami, Neel" <neelk@cswcasa.com>
To: "'Rolf Wester'" <rolf.wester@ilt.fhg.de>, caml-list@inria.fr
Subject: RE: [Caml-list] Warning: this match case is unused.
Date: Thu, 8 Nov 2001 11:29:01 -0500	[thread overview]
Message-ID: <B1E4D3274D57D411BE8400D0B783FF32A8D596@exchange1.cswv.com> (raw)

Rolf Wester [mailto:rolf.wester@ilt.fhg.de] wrote:
> 
> this is probably a trivial question but can someone tell me why:
>  
> let f l n0 =
>   let n = List.length l in
>   match n with 
> 	  n0 -> 1;
> 	| _  ->  0;;
> 
> Results in:
> Warning: this match case is unused.

Yes. Your function will always return 1, because variables on the
left-hand side of a pattern-match are bound like in a let expression. 
So the first branch of the match will always succeed, binding n0 to n, 
and then return 1.

So your code is equivalent to:

let f l n0 = 
  let n = List.length l in
  let n0 = n
  in 1

which is probably not what you want. :) Try writing this as:

let f l n0 = 
  let n = List.length l in 
  if n = n0 then
    1
  else
    0

--
Neel Krishnaswami
neelk@cswcasa.com
 
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


             reply	other threads:[~2001-11-08 16:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-08 16:29 Krishnaswami, Neel [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-11-09  6:39 Rolf Wester
2001-11-08 14:55 Rolf Wester
2001-11-08 16:14 ` Pixel
2001-11-08 16:21 ` Yann Coscoy

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=B1E4D3274D57D411BE8400D0B783FF32A8D596@exchange1.cswv.com \
    --to=neelk@cswcasa.com \
    --cc=caml-list@inria.fr \
    --cc=rolf.wester@ilt.fhg.de \
    /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;
as well as URLs for NNTP newsgroup(s).