From: Jacques Le Normand <rathereasy@gmail.com>
To: Markus Weissmann <markus.weissmann@in.tum.de>
Cc: OCaml mailing list <caml-list@inria.fr>
Subject: Re: [Caml-list] Exhaustiveness, currying with GADTs
Date: Thu, 11 Oct 2012 12:04:02 -0700 [thread overview]
Message-ID: <CAK0y-37vdU_FPBCPdPV_hF1+LE7QCoW2DQLARsfkOYr_3-rjyA@mail.gmail.com> (raw)
In-Reply-To: <800E1F0B-8658-49A2-BA12-88F760F5E083@in.tum.de>
2) seems to be the value restriction. basically, only constructors,
composition of constructors and lambdas can generalize.
What warning are you getting for 1) ?
On Thu, Oct 11, 2012 at 10:30 AM, Markus Weissmann
<markus.weissmann@in.tum.de> wrote:
> Hello,
>
> while playing around with GADTs, I came across two issues I don't understand: The exhaustiveness check and currying functions.
> 1.) I get a warning about my match (in function "componentwise") not being exhaustive, while imho it obviously is:
>
> --------8<----------
> type d2
> type d3
>
> type _ t =
> | Vector2 : (float * float) -> d2 t
> | Vector3 : (float * float * float) -> d3 t
>
> let componentwise : type d . (float -> float -> float) -> d t -> d t -> d t = fun f v1 v2 ->
> match (v1, v2) with
> | (Vector2 (x1, y1), Vector2 (x2, y2)) -> Vector2 (f x1 x2, f y1 y1)
> | (Vector3 (x1, y1, z1), Vector3 (x2, y2, z2)) -> Vector3 (f x1 x2, f y1 y1, f z1 z2)
> -------->8----------
>
> 2.) When I use "componentwise" for other functions, I cannot do this:
>
> let add = componentwise (+.)
>
> ("contains type variables that cannot be generalized")
> Fair enough. But I also cannot do this:
>
> let add : type d . d t -> d t -> d t = componentwise (+.)
>
> ("This definition has type 'd t -> 'd t -> 'd t which is less general than 'd0. 'd0 t -> 'd0 t -> 'd0 t")
> Only the "full" version works:
>
> let add : type d . d t -> d t -> d t = fun v1 v2 -> componentwise (+.) v1 v2
>
>
> I would be very happy if someone could shed some light especially on 1.).
>
>
> Thanks & regards
> -Markus
>
> --
> Markus Weißmann, M.Sc.
> Technische Universität München
> Institut für Informatik
> Boltzmannstr. 3
> D-85748 Garching
> Germany
> http://wwwknoll.in.tum.de/
>
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
next prev parent reply other threads:[~2012-10-11 19:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-11 17:30 Markus Weissmann
2012-10-11 19:04 ` Jacques Le Normand [this message]
2012-10-11 19:23 ` "Markus W. Weißmann"
2012-10-12 5:42 ` Jacques Garrigue
2012-10-12 8:57 ` "Markus W. Weißmann"
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=CAK0y-37vdU_FPBCPdPV_hF1+LE7QCoW2DQLARsfkOYr_3-rjyA@mail.gmail.com \
--to=rathereasy@gmail.com \
--cc=caml-list@inria.fr \
--cc=markus.weissmann@in.tum.de \
/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