From: Patrick M Doane <patrick@watson.org>
To: Pierre Weis <Pierre.Weis@inria.fr>
Cc: Markus Mottl <mottl@miss.wu-wien.ac.at>, caml-list@inria.fr
Subject: Re: Typing of patterns
Date: Mon, 5 Jun 2000 21:10:45 -0400 (EDT) [thread overview]
Message-ID: <Pine.BSF.3.96.1000605204225.15847A-100000@fledge.watson.org> (raw)
In-Reply-To: <200006051356.PAA17512@pauillac.inria.fr>
On Mon, 5 Jun 2000, Pierre Weis wrote:
> However, we get a strange difference in typing since, as you
> mentioned, the explicit ``as clause'' does not set up a typing
> connection between input and output :
>
> let (ensure_nil : 'a pliste -> 'b pliste) = function
> | `Cons (x, l) -> failwith "Not nil"
> | `Nil as l -> l;;
> val ensure_nil : 'a pliste -> 'b pliste = <fun>
>
> Jacques may explain us if the above suggested generalization scheme is
> used for identifiers bound in as clauses of patterns (and if not,
> which scheme is used ?)...
This discussion seems related to a recent typing difficulty I have had
with polymorphic variants.
I want to change the data associated to a particular constructor of a
variant and leave the others unmodified:
# let f = function `A -> `A () | _ as t -> t;;
Characters 41-42:
This expression has type [< `A | ..] but is here used with type
[> `A of unit]
Notice that the type for '_' includes `A when it obviously cannot. One
could include every possible expected type in place of '_' but that
removes one of the advantages of polymorphic variants: that the type can
be refined and extended easily.
While further exploring this issue I managed to get an uncaught exception
from the type checker:
# let f = function `A true -> () | `A 5 -> ();;
Uncaught exception: File "typing/parmmatch.ml", ...
Taking the conjuction of 'unit' and 'int' does seem to work however,
# let f = function `A -> () | `A 5 -> ();;
val f : [< `A of & int] -> unit = <fun>
but it prints the type without mentioning 'unit'.
Patrick Doane
next prev parent reply other threads:[~2000-06-06 7:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-06-01 13:23 Markus Mottl
2000-06-05 13:56 ` Pierre Weis
2000-06-05 15:29 ` Markus Mottl
2000-06-06 0:55 ` Jacques Garrigue
2000-06-06 15:32 ` Pierre Weis
2000-06-06 1:10 ` Patrick M Doane [this message]
2000-06-06 8:55 ` Jacques Garrigue
2000-06-06 7:24 Pierre Weis
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=Pine.BSF.3.96.1000605204225.15847A-100000@fledge.watson.org \
--to=patrick@watson.org \
--cc=Pierre.Weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=mottl@miss.wu-wien.ac.at \
/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