Google Groups Home Help | Sign in
parameterized pattern
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all
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, 4:19 pm
Newsgroups: fa.caml
From: Serge Aleynikov <se...@hq.idt.net>
Date: Mon, 06 Nov 2006 21:19:10 UTC
Local: Mon, Nov 6 2006 4:19 pm
Subject: [Caml-list] parameterized pattern
Hi,

The section 6.6 of OCaml's manual introduces a notion of "Parenthesized
patterns".

I couldn't find any examples on how to use this feature, and brute-force
approach doesn't work:

# match 1.0 with
  (y : float)  -> print_float y
| (s : string) -> print_string s;;
This pattern matches values of type string
but is here used to match values of type float
#

Could anyone point at a suitable resource?

Thanks.

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.
Jon Harrop  
View profile
 More options Nov 6 2006, 7:03 pm
Newsgroups: fa.caml
From: Jon Harrop <j...@ffconsultancy.com>
Date: Tue, 07 Nov 2006 00:03:11 UTC
Local: Mon, Nov 6 2006 7:03 pm
Subject: Re: [Caml-list] parameterized pattern
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. 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>

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists

_______________________________________________
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.
Martin Jambon  
View profile
 More options Nov 6 2006, 7:07 pm
Newsgroups: fa.caml
From: Martin Jambon <martin1...@laposte.net>
Date: Tue, 07 Nov 2006 00:07:20 UTC
Local: Mon, Nov 6 2006 7:07 pm
Subject: Re: [Caml-list] parameterized pattern

What you wrote is equivalent to:

match ((1.0 : float) : string) with
    y -> print_float y
  | s -> print_string s

In OCaml, match-with is a test against the structure of a value, not its
type. What you want to do is not currently possible in OCaml.

Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr

_______________________________________________
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.
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.

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.
Lukasz Stafiniak  
View profile
 More options Nov 8 2006, 6:58 pm
Newsgroups: fa.caml
From: "Lukasz Stafiniak" <lukst...@gmail.com>
Date: Wed, 08 Nov 2006 23:58:54 UTC
Local: Wed, Nov 8 2006 6:58 pm
Subject: Re: [Caml-list] parameterized pattern
You can do this kind of ad-hoc polymorphism with with G'Caml:

http://web.yl.is.s.u-tokyo.ac.jp/~furuse/gcaml/

BTW, I think that G'Caml deserves more attention on this list (see
http://lambda-the-ultimate.org/node/1278). (I've even thought that it
is still a patch to OCaml 2.0, but it seems to be up-to-date now.)

You can check also a related attempt in Meta OCaml, by Oleg Kiselyov:

http://pobox.com/~oleg/ftp/ML/gprint/

(search the archives for "Generic print function").

On 11/6/06, Serge Aleynikov <se...@hq.idt.net> wrote:

_______________________________________________
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.
brogoff  
View profile
 More options Nov 8 2006, 8:48 pm
Newsgroups: fa.caml
From: brogoff <brog...@speakeasy.net>
Date: Thu, 09 Nov 2006 01:48:22 UTC
Local: Wed, Nov 8 2006 8:48 pm
Subject: Re: [Caml-list] parameterized pattern

On Thu, 9 Nov 2006, Lukasz Stafiniak wrote:
> You can do this kind of ad-hoc polymorphism with with G'Caml:

> http://web.yl.is.s.u-tokyo.ac.jp/~furuse/gcaml/

> BTW, I think that G'Caml deserves more attention on this list (see
> http://lambda-the-ultimate.org/node/1278). (I've even thought that it
> is still a patch to OCaml 2.0, but it seems to be up-to-date now.)

The GCaml docs say (and have said for at least a year) that it doesn't support
all of OCaml, neither objects nor polymorphic variants. I'd guess that
it doesn't support recursive modules either.

It's a pity, as I've often wished that OCaml supported the extensional
polymorphism that GCaml has, but I don't think that's going to happen.
It would probaby make more sense to create a separate language at this
point, since OCaml is complicated enough.

-- Brian

_______________________________________________
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.
Jon Harrop  
View profile
 More options Nov 9 2006, 12:24 am
Newsgroups: fa.caml
From: Jon Harrop <j...@ffconsultancy.com>
Date: Thu, 09 Nov 2006 05:24:00 UTC
Subject: Re: [Caml-list] parameterized pattern
On Wednesday 08 November 2006 23:55, Lukasz Stafiniak wrote:

> You can do this kind of ad-hoc polymorphism with with G'Caml:

> http://web.yl.is.s.u-tokyo.ac.jp/~furuse/gcaml/

> BTW, I think that G'Caml deserves more attention on this list (see
> http://lambda-the-ultimate.org/node/1278). (I've even thought that it
> is still a patch to OCaml 2.0, but it seems to be up-to-date now.)

I am certainly interested in GCaml but:

 Where do you get it from (the CVS doesn't seem to have it)?
 How fast is it?
 Does it support native code?
 What version of OCaml is it based upon?

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists

_______________________________________________
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.
skaller  
View profile
 More options Nov 9 2006, 3:54 am
Newsgroups: fa.caml
From: skaller <skal...@users.sourceforge.net>
Date: Thu, 09 Nov 2006 08:54:33 UTC
Local: Thurs, Nov 9 2006 3:54 am
Subject: Re: [Caml-list] parameterized pattern

On Thu, 2006-11-09 at 05:19 +0000, Jon Harrop wrote:
> On Thursday 09 November 2006 01:45, brogoff wrote:
> > It's a pity, as I've often wished that OCaml supported the extensional
> > polymorphism that GCaml has, but I don't think that's going to happen.
> > It would probaby make more sense to create a separate language at this
> > point, since OCaml is complicated enough.

> I think F# provides some form of extensional polymorphism. I'm not convinced
> that it is a good idea yet...

Well FYI Felix has traditional (open) overloading, but since it
doesn't allow traditional C++ style dependent name lookup because
that would destroy parametricity of polymorphic functions,
something else was needed.

So it now has first order typeclasses to solve this problem.
[By first order I mean typeclass arguments can be types but
not type constructors, i.e. it only supports data polymorphism,
not functorial polymorphism/polyadic programming]

This allows you to write stuff like this:

typeclass Integer[t] {
  virtual fun add: t * t -> t;

}

fun sum3[t where Integer[t]] (x:t,y:t,z:t)=> add(x,add(y,z));

print (sum3(1,2,3));

instance Integer[int] {
  fun add: int * int -> int = "$1+$2"; // C code

}

open Integer[int];

print (add(add(1,2),3));

I'm not sure i really like typeclasses much, ML functors
seem more general, and the coupling is explicit.

--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

_______________________________________________
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.
brogoff  
View profile
 More options Nov 9 2006, 11:29 am
Newsgroups: fa.caml
From: brogoff <brog...@speakeasy.net>
Date: Thu, 09 Nov 2006 16:29:49 UTC
Local: Thurs, Nov 9 2006 11:29 am
Subject: Re: [Caml-list] parameterized pattern

On Thu, 9 Nov 2006, skaller wrote:
> On Thu, 2006-11-09 at 05:19 +0000, Jon Harrop wrote:
> > On Thursday 09 November 2006 01:45, brogoff wrote:
> > > It's a pity, as I've often wished that OCaml supported the extensional
> > > polymorphism that GCaml has, but I don't think that's going to happen.
> > > It would probaby make more sense to create a separate language at this
> > > point, since OCaml is complicated enough.

> > I think F# provides some form of extensional polymorphism.

I just did a quick scan of some F# docs and I saw nothing. What did you have in
mind?

> > I'm not convinced that it is a good idea yet...

For almost any given language feature, there will be people who like it, and
people who don't. Do you think having class based OO in OCaml is a good idea?
I find it useful, especially since OCaml records are far too restrictive, but
I hope that in some future ML that there are other approaches as the
class/object system is complex, and the interactions with "core ML + modules"
is tricky.

That said, the class system is being used and it won't go away, and some
people really like it.

> Well FYI Felix has traditional (open) overloading, but since it
> doesn't allow traditional C++ style dependent name lookup because
> that would destroy parametricity of polymorphic functions,
> something else was needed.

> So it now has first order typeclasses to solve this problem.

Did you consider GCaml style generic functions?

-- Brian

_______________________________________________
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.
micha  
View profile
 More options Nov 9 2006, 11:45 am
Newsgroups: fa.caml
From: micha <mich...@fantasymail.de>
Date: Thu, 09 Nov 2006 16:45:30 UTC
Local: Thurs, Nov 9 2006 11:45 am
Subject: Re: [Caml-list] parameterized pattern
Jon Harrop schrieb:

> I am certainly interested in GCaml but:

> . Where do you get it from (the CVS doesn't seem to have it)?

I did:

export CVSROOT=:pserver:anon...@camlcvs.inria.fr:/caml
cvs login
 >empty password
cvs co -r gcaml3090 ocaml

this gives me an ocaml source with gcamllib and README.gcaml...
Maybe this is the right source...

cheers
 Michael

_______________________________________________
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.
skaller  
View profile
 More options Nov 9 2006, 12:59 pm
Newsgroups: fa.caml
From: skaller <skal...@users.sourceforge.net>
Date: Thu, 09 Nov 2006 17:59:50 UTC
Local: Thurs, Nov 9 2006 12:59 pm
Subject: Re: [Caml-list] parameterized pattern

On Thu, 2006-11-09 at 08:22 -0800, brogoff wrote:
> On Thu, 9 Nov 2006, skaller wrote:
[]
> > So it now has first order typeclasses to solve this problem.

> Did you consider GCaml style generic functions?

Yes, but they seem a bit harder to implement.
The closure is nice though. The example has a type like:

{ 'a -> 'a -> 'a < [| int -> int -> int
| float -> float -> float |] }

but I don't know how to unify alternatives.

Feels a bit like a GLR parser .. you fork the unification
with each case, drop a thread when unification fails,
and merge successes into alternatives?

--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

_______________________________________________
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.
Don Syme  
View profile
 More options Nov 14 2006, 6:15 pm
Newsgroups: fa.caml
From: "Don Syme" <Don.S...@microsoft.com>
Date: Tue, 14 Nov 2006 23:15:15 UTC
Local: Tues, Nov 14 2006 6:15 pm
Subject: RE: [Caml-list] p