caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Typing problem
@ 2000-02-10 13:49 jean-marc alliot
  2000-02-11 10:17 ` Pierre Weis
  0 siblings, 1 reply; 13+ messages in thread
From: jean-marc alliot @ 2000-02-10 13:49 UTC (permalink / raw)
  To: caml-list

We recently found a quite annoying problem with the typing system in
ocaml 2.99, and Jacques Garrigue explained it to us very kindly. Other
people might be be interested however.

The problem is summarized in the following code:

First let's define two types:
type t1 = (?l:int -> unit -> unit)
type t = Toto of t1

Then the function:
let f1 g =
  g l:3 ();
  (Toto g);;

This function doesn't compile and the compiler error message is somewhat
cryptic at first sight:
File "toto.ml", line 11, characters 8-9:
This expression has type int -> unit -> 'a but is here used with type
  t1 = ?l:int -> unit -> unit

To make it compile, you have to type explicitly g with:
let f2 (g : t1) =
  g l:3 ();
  (Toto g);;

We would very much like to see this clearly documented in ocaml 2.99
reference manual, as it is a serious change in the behavior of the
typing system. Determinism is lost, as typing f1 would succeed if typing
was done in reverse order (from last line to first line).
Perhaps also a different error message from the compiler would help in
detecting such problems.


P Brisset
JM Alliot





^ permalink raw reply	[flat|nested] 13+ messages in thread
* Typing problem
@ 2006-03-19  1:30 Daniel Bünzli
  0 siblings, 0 replies; 13+ messages in thread
From: Daniel Bünzli @ 2006-03-19  1:30 UTC (permalink / raw)
  To: Caml list

Hello,

I would like to define the following types.

> type u = [ `U1 | `U2 ]
>
> type 'a t = [`A of 'a | `B of ([`U1 ] as 'a) ] constraint 'a = [< u ]

t's parameter is used to statically express constraints in other  
parts of the code. My problem is that
the constraint on 'a is downgraded to [`U1] while I would like to be  
able to write

> let param : 'a t -> 'a = function (`A v | `B v) -> v

and get the following typing behaviour.

> let v = param (`A `U1) (* should type *)
> let v = param (`A `U2) (* should type *)
> let v = param (`B `U1) (* should type *)
> let v = param (`B `U2) (* should not type *)

Is it possible to express that in ocaml's type system ?

Regards,

Daniel


^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Typing problem
@ 2006-03-19 14:23 j h woodyatt
  0 siblings, 0 replies; 13+ messages in thread
From: j h woodyatt @ 2006-03-19 14:23 UTC (permalink / raw)
  To: Daniel Bünzli; +Cc: The Caml Trade

Daniel Bünzli <daniel.buenzli@epfl.ch>
>
> I would like to define the following types.
>
>> type u = [ `U1 | `U2 ]
>> type 'a t = [`A of 'a | `B of ([`U1 ] as 'a) ] constraint 'a = [< u ]
>
> t's parameter is used to statically express constraints in other  
> parts of the code. My problem is that the constraint on 'a is  
> downgraded to [`U1] while I would like to be able to write
>
>> let param : 'a t -> 'a = function (`A v | `B v) -> v
>
> and get the following typing behaviour.
>
>> let v = param (`A `U1) (* should type *)
>> let v = param (`A `U2) (* should type *)
>> let v = param (`B `U1) (* should type *)
>> let v = param (`B `U2) (* should not type *)
>
> Is it possible to express that in ocaml's type system ?

The short answer is no.  The reason is that 'a is not the same type  
in the `A case as in the `B case.  Type t really has two type  
parameters.  (Well, it can have only one if this contrived example is  
fully representative of your code, as I'll describe below).

type ('a, 'b) t = [ `A of 'a | `B of 'b ]
   constraint 'a = [< u ] constraint 'b = [ `U1 ]

However, 'b is concrete in your example, so-- if it's fully  
representative of your code-- you could just do this, and you would  
still have only one type parameter:

type 'a t = [ `A of 'a | `B of [ `U1 ] ]
   constraint 'a = [< u ]

—
j h woodyatt <jhw@conjury.org>




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

end of thread, other threads:[~2006-03-19 14:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-10 13:49 Typing problem jean-marc alliot
2000-02-11 10:17 ` Pierre Weis
2000-02-12 22:34   ` Jacques Garrigue
2000-02-14  8:04     ` Thread feature missing Christophe Raffalli
2000-02-14 15:11       ` Gerd Stolpmann
2000-02-15 16:06       ` Xavier Leroy
2000-02-16 11:31         ` Christophe Raffalli
2000-02-18  9:14           ` Xavier Leroy
2000-02-21 20:38             ` skaller
2000-02-22 11:15               ` Some questions about floatting point issues jean-marc alliot
2000-02-25 16:04                 ` Xavier Leroy
2006-03-19  1:30 Typing problem Daniel Bünzli
2006-03-19 14:23 j h woodyatt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).