From: "Hezekiah M. Carty" <hcarty@atmos.umd.edu>
To: ben kuin <benkuin@gmail.com>
Cc: Philip <feucht@uni-koblenz.de>, caml-list@inria.fr
Subject: Re: [Caml-list] from if...else to pattern matching
Date: Sat, 2 Oct 2010 12:09:17 -0400 [thread overview]
Message-ID: <AANLkTimp6OxMnYKrjon1=EnaS4OpCf9sHvQVVyo6D9e=@mail.gmail.com> (raw)
In-Reply-To: <AANLkTikkFytjyRzE=_NJUq2g6KV6wAR8v7QOwyshHUnj@mail.gmail.com>
On Sat, Oct 2, 2010 at 10:47 AM, ben kuin <benkuin@gmail.com> wrote:
>>
>> # let t x = match x with
>> a when x<=4 -> true
>> | _ -> false;;
>>
>
> ok, I had a similar attempt with
>
> let tt x = function
> a when x<=4 -> true
> | _ -> false;;
>
> but that gave me the following (scary -> 'a -> ) signature
>
> val tt : int -> 'a -> bool = <fun>
>
> so I stopped
>
> thanks anyway
>
This seems to be a common beginner mistake (hence the reference to the
beginner's list). You defined tt as a function which takes two
arguments, x and another matched by "function" - which tt ignores the
value of (a when x <= 4). The pattern-matched value is never used,
therefore it can be any type.
Hope this helps,
Hez
next prev parent reply other threads:[~2010-10-02 16:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-02 14:04 ben kuin
2010-10-02 14:22 ` [Caml-list] " Philip
2010-10-02 14:47 ` ben kuin
2010-10-02 16:09 ` Hezekiah M. Carty [this message]
2010-10-02 17:54 ` Jon Harrop
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='AANLkTimp6OxMnYKrjon1=EnaS4OpCf9sHvQVVyo6D9e=@mail.gmail.com' \
--to=hcarty@atmos.umd.edu \
--cc=benkuin@gmail.com \
--cc=caml-list@inria.fr \
--cc=feucht@uni-koblenz.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).