Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] parameterized pattern
Date: Mon, 6 Nov 2006 23:58:54 +0000	[thread overview]
Message-ID: <200611062358.54696.jon@ffconsultancy.com> (raw)
In-Reply-To: <454FA5F8.5030106@hq.idt.net>

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


  reply	other threads:[~2006-11-07  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-06 21:15 Serge Aleynikov
2006-11-06 23:58 ` Jon Harrop [this message]
2006-11-07  0:12   ` [Caml-list] " Serge Aleynikov
2006-11-06 23:59 ` Martin Jambon
2006-11-08 23:55 ` Lukasz Stafiniak
2006-11-09  1:45   ` brogoff
2006-11-09  5:19     ` Jon Harrop
2006-11-09  8:51       ` skaller
2006-11-09 16:22         ` brogoff
2006-11-09 17:55           ` skaller
2006-11-14 23:12           ` Don Syme
2006-11-15  1:00             ` brogoff
2006-11-15  1:36               ` Don Syme
2006-11-09  5:18   ` Jon Harrop
2006-11-09 16:42     ` micha

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=200611062358.54696.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --cc=caml-list@yquem.inria.fr \
    /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