caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] constructor disambiguation for gadts
@ 2014-10-07 16:14 Milan Stanojević
  2014-10-08  3:29 ` Jacques Garrigue
  2014-10-14 12:34 ` Goswin von Brederlow
  0 siblings, 2 replies; 4+ messages in thread
From: Milan Stanojević @ 2014-10-07 16:14 UTC (permalink / raw)
  To: Caml List

I was wondering what are technical difficulties that prevent
constructor disambiguation for GADTs?

I got an interesting error today, where it is clear that compiler
knows the type but because it is GADT it is still asking me to qualify
the constructor.

Here is the simple example.
module A : sig
  type _ t =
    | I : int t
    | S : string t
end = struct
  type _ t =
    | I : int t
    | S : string t
end

let add : type a . a A.t -> a -> a -> a =
  fun w a1 a2 ->
    match w with
    | I -> a1 + a2
    | S -> String.concat "" [a1; a2]
;;

I get File "foo.ml", line 14, characters 6-7:
Error: The GADT constructor I of type A.t must be qualified in this pattern.

I'm not sure what extra information I'm giving to the type checker by
qualifying the constructor.

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

* Re: [Caml-list] constructor disambiguation for gadts
  2014-10-07 16:14 [Caml-list] constructor disambiguation for gadts Milan Stanojević
@ 2014-10-08  3:29 ` Jacques Garrigue
  2014-10-08 16:05   ` Milan Stanojević
  2014-10-14 12:34 ` Goswin von Brederlow
  1 sibling, 1 reply; 4+ messages in thread
From: Jacques Garrigue @ 2014-10-08  3:29 UTC (permalink / raw)
  To: Milan Stanojević; +Cc: OCaML List Mailing

On 2014/10/08 01:14, Milan Stanojević wrote:
> 
> I was wondering what are technical difficulties that prevent
> constructor disambiguation for GADTs?
> 
> I got an interesting error today, where it is clear that compiler
> knows the type but because it is GADT it is still asking me to qualify
> the constructor.
> 
> Here is the simple example.
> module A : sig
>  type _ t =
>    | I : int t
>    | S : string t
> end = struct
>  type _ t =
>    | I : int t
>    | S : string t
> end
> 
> let add : type a . a A.t -> a -> a -> a =
>  fun w a1 a2 ->
>    match w with
>    | I -> a1 + a2
>    | S -> String.concat "" [a1; a2]
> ;;
> 
> I get File "foo.ml", line 14, characters 6-7:
> Error: The GADT constructor I of type A.t must be qualified in this pattern.
> 
> I'm not sure what extra information I'm giving to the type checker by
> qualifying the constructor.

Typing of GADT patterns follows a slightly different path, which makes
harder to insert constructor disambiguation.
To be more precise, the type-checker first looks at the patterns, and
tries to guess whether there are some GADT constructors inside it.
If some constructors are ambiguous, it may guess wrongly that there
are none, and take the non-GADT path, to find later that it should have
taken the GADT path.

Jacques Garrigue

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

* Re: [Caml-list] constructor disambiguation for gadts
  2014-10-08  3:29 ` Jacques Garrigue
@ 2014-10-08 16:05   ` Milan Stanojević
  0 siblings, 0 replies; 4+ messages in thread
From: Milan Stanojević @ 2014-10-08 16:05 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: OCaML List Mailing

Thanks for the answer.
Is there any hope this might get fixed in the future?

On Tue, Oct 7, 2014 at 11:29 PM, Jacques Garrigue
<garrigue@math.nagoya-u.ac.jp> wrote:
> On 2014/10/08 01:14, Milan Stanojević wrote:
>>
>> I was wondering what are technical difficulties that prevent
>> constructor disambiguation for GADTs?
>>
>> I got an interesting error today, where it is clear that compiler
>> knows the type but because it is GADT it is still asking me to qualify
>> the constructor.
>>
>> Here is the simple example.
>> module A : sig
>>  type _ t =
>>    | I : int t
>>    | S : string t
>> end = struct
>>  type _ t =
>>    | I : int t
>>    | S : string t
>> end
>>
>> let add : type a . a A.t -> a -> a -> a =
>>  fun w a1 a2 ->
>>    match w with
>>    | I -> a1 + a2
>>    | S -> String.concat "" [a1; a2]
>> ;;
>>
>> I get File "foo.ml", line 14, characters 6-7:
>> Error: The GADT constructor I of type A.t must be qualified in this pattern.
>>
>> I'm not sure what extra information I'm giving to the type checker by
>> qualifying the constructor.
>
> Typing of GADT patterns follows a slightly different path, which makes
> harder to insert constructor disambiguation.
> To be more precise, the type-checker first looks at the patterns, and
> tries to guess whether there are some GADT constructors inside it.
> If some constructors are ambiguous, it may guess wrongly that there
> are none, and take the non-GADT path, to find later that it should have
> taken the GADT path.
>
> Jacques Garrigue

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

* Re: [Caml-list] constructor disambiguation for gadts
  2014-10-07 16:14 [Caml-list] constructor disambiguation for gadts Milan Stanojević
  2014-10-08  3:29 ` Jacques Garrigue
@ 2014-10-14 12:34 ` Goswin von Brederlow
  1 sibling, 0 replies; 4+ messages in thread
From: Goswin von Brederlow @ 2014-10-14 12:34 UTC (permalink / raw)
  To: caml-list

On Tue, Oct 07, 2014 at 12:14:01PM -0400, Milan Stanojevi?? wrote:
> I was wondering what are technical difficulties that prevent
> constructor disambiguation for GADTs?
> 
> I got an interesting error today, where it is clear that compiler
> knows the type but because it is GADT it is still asking me to qualify
> the constructor.
> 
> Here is the simple example.
> module A : sig
>   type _ t =
>     | I : int t
>     | S : string t
> end = struct
>   type _ t =
>     | I : int t
>     | S : string t
> end
> 
> let add : type a . a A.t -> a -> a -> a =
>   fun w a1 a2 ->
>     match w with
>     | I -> a1 + a2
>     | S -> String.concat "" [a1; a2]
> ;;
> 
> I get File "foo.ml", line 14, characters 6-7:
> Error: The GADT constructor I of type A.t must be qualified in this pattern.
> 
> I'm not sure what extra information I'm giving to the type checker by
> qualifying the constructor.

Shouldn't that be A.I and A.S? You didn't open module A.

MfG
	Goswin

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

end of thread, other threads:[~2014-10-14 12:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-07 16:14 [Caml-list] constructor disambiguation for gadts Milan Stanojević
2014-10-08  3:29 ` Jacques Garrigue
2014-10-08 16:05   ` Milan Stanojević
2014-10-14 12:34 ` Goswin von Brederlow

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).