Version franÁaise
Home ††† About ††† Download ††† Resources ††† Contact us †††
Browse thread
from if...else to pattern matching
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Hezekiah M. Carty <hcarty@a...>
Subject: Re: [Caml-list] from if...else to pattern matching
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