Google Groups Home
Help | Sign in
Message from discussion parameterized pattern
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Serge Aleynikov  
View profile
 More options Nov 6 2006, 7:17 pm
Newsgroups: fa.caml
From: Serge Aleynikov <se...@hq.idt.net>
Date: Tue, 07 Nov 2006 00:17:24 UTC
Local: Mon, Nov 6 2006 7:17 pm
Subject: Re: [Caml-list] parameterized pattern
Jon Harrop wrote:
> On Monday 06 November 2006 21:15, Serge Aleynikov wrote:

>> Could anyone point at a suitable resource?

> I wasn't even aware that you could add type annotations inside a pattern.

I had a similar reaction when I saw that construct in the formal
language spec.
> Your
> example will not work simply because OCaml's type system will not allow float
> to unify with string. You need some context where type inference will allow
> different possibilities, like a tuple containing both a float and a string:

> # let f = function
>   | (y : float), _ -> print_float y
>   | _, (s : string) -> print_string s;;

> or a polymorphic variant containing either a float or a string:

> # let f = function
>   | `F (y : float) -> print_float y
>   | `S (s : string) -> print_string s;;
> val f : [< `F of float | `S of string ] -> unit = <fun>

Thanks.  Several people also replied clarifying that the type
annotations were merely used for aiding the type inferencer.

Serge

--
Serge Aleynikov
Routing R&D, IDT Telecom
Tel: +1 (973) 438-3436
Fax: +1 (973) 438-1464

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google