Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] Exhaustiveness, currying with GADTs
@ 2012-10-11 17:30 Markus Weissmann
  2012-10-11 19:04 ` Jacques Le Normand
  2012-10-12  5:42 ` Jacques Garrigue
  0 siblings, 2 replies; 5+ messages in thread
From: Markus Weissmann @ 2012-10-11 17:30 UTC (permalink / raw)
  To: OCaml mailing list

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/


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-10-12  8:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-11 17:30 [Caml-list] Exhaustiveness, currying with GADTs Markus Weissmann
2012-10-11 19:04 ` Jacques Le Normand
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"

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox