From: "Olivier Pérès" <olivier.peres@laposte.net>
To: Caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Polymorphic variant typing
Date: Tue, 15 Feb 2005 23:21:33 +0100 [thread overview]
Message-ID: <421275ED.1060607@laposte.net> (raw)
In-Reply-To: <7bf1f3b95c18eeda0ed169eb7f73d6f0@urbanet.ch>
Gilles Dubochet a écrit :
> let incr g x = match x with
> | `Int i -> `Int (i+1)
> | x -> (g x);;
>
> Receives type:
> (([> `Int of int ] as 'a) -> ([> `Int of int ] as 'b)) -> 'a -> 'b
Now, how about this :
let incr x g = match x with
| `Int i -> `Int (i+1)
| x -> g x;;
Doesn't it look like your code ? OCaml 3.08.2 types it as follows :
val incr : ([> `Int of int ] as 'a) -> ('a -> ([> `Int of int ] as 'b))
-> 'b = <fun>
This is more like it !
incr (`Int 1) (fun (`Int i) -> (`Int (i+1)));;
- : [> `Int of int ] = `Int 2
incr (`Float 1.0) (fun x -> match x with (`Float f) -> (`Float (f +.
1.0)) | x -> x);;
- : [> `Float of float | `Int of int ] = `Float 2.
It remains to understand why the type of incr should depend upon the
order in which the arguments are given...
Yours,
Olivier.
next prev parent reply other threads:[~2005-02-15 22:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-15 21:28 Gilles Dubochet
2005-02-15 22:21 ` Olivier Pérès [this message]
2005-02-15 23:15 ` [Caml-list] " Gilles Dubochet
2005-02-16 0:36 ` Jacques Garrigue
2005-02-16 1:21 ` Gilles Dubochet
2005-02-16 6:40 ` Jacques Garrigue
2005-02-16 10:12 ` Radu Grigore
2005-02-16 0:43 ` David Brown
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=421275ED.1060607@laposte.net \
--to=olivier.peres@laposte.net \
--cc=caml-list@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