caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Typing problem with polymorphic variants
@ 2003-04-01 17:34 Alessandro Baretta
  2003-04-01 18:38 ` Ville-Pertti Keinonen
  2003-04-01 18:44 ` David Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Alessandro Baretta @ 2003-04-01 17:34 UTC (permalink / raw)
  To: Ocaml

This just baffles me.

 > Values do not match:
 >   val feature :
 >     [> `Clear | `Length of int | `Pitch of int
 >               | `Width of 'a] -> string
 > is not included in
 >   val feature : [> `Clear] -> string

Why are "match-anything" functions of the kind of

let f = function
   | `Foo -> "foo"
   | `Bar -> "bar"
   | _ -> "?"

incompatible with signatures like

val f : [> `Foo ] -> string
?


There clearly is no case when a value of type [> `Foo] will 
not be acceptable for f. So why does the type checker reject 
this?

Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Typing problem with polymorphic variants
  2003-04-01 18:38 ` Ville-Pertti Keinonen
@ 2003-04-01 17:56   ` Alessandro Baretta
  0 siblings, 0 replies; 5+ messages in thread
From: Alessandro Baretta @ 2003-04-01 17:56 UTC (permalink / raw)
  To: Ville-Pertti Keinonen, Ocaml



Ville-Pertti Keinonen wrote:
> 
> On Tuesday, Apr 1, 2003, at 20:34 Europe/Helsinki, Alessandro Baretta 
> wrote:
> 
>> This just baffles me.
>>
>> > Values do not match:
>> >   val feature :
>> >     [> `Clear | `Length of int | `Pitch of int
>> >               | `Width of 'a] -> string
>> > is not included in
>> >   val feature : [> `Clear] -> string
> 
> 
> Consider what would happen if you tried to pass a `Length of float, 
> which is acceptable according to the latter signature.
> 
> 

Thank you very much.

This is actually a meaningful comment. I wonder if there is 
any sensible way to do what I'm trying to do.

I'll think it over.

Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Typing problem with polymorphic variants
  2003-04-01 17:34 [Caml-list] Typing problem with polymorphic variants Alessandro Baretta
@ 2003-04-01 18:38 ` Ville-Pertti Keinonen
  2003-04-01 17:56   ` Alessandro Baretta
  2003-04-01 18:44 ` David Brown
  1 sibling, 1 reply; 5+ messages in thread
From: Ville-Pertti Keinonen @ 2003-04-01 18:38 UTC (permalink / raw)
  To: Alessandro Baretta; +Cc: Ocaml


On Tuesday, Apr 1, 2003, at 20:34 Europe/Helsinki, Alessandro Baretta 
wrote:

> This just baffles me.
>
> > Values do not match:
> >   val feature :
> >     [> `Clear | `Length of int | `Pitch of int
> >               | `Width of 'a] -> string
> > is not included in
> >   val feature : [> `Clear] -> string

Consider what would happen if you tried to pass a `Length of float, 
which is acceptable according to the latter signature.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Typing problem with polymorphic variants
  2003-04-01 17:34 [Caml-list] Typing problem with polymorphic variants Alessandro Baretta
  2003-04-01 18:38 ` Ville-Pertti Keinonen
@ 2003-04-01 18:44 ` David Brown
  2003-04-02  1:34   ` Jacques Garrigue
  1 sibling, 1 reply; 5+ messages in thread
From: David Brown @ 2003-04-01 18:44 UTC (permalink / raw)
  To: Alessandro Baretta; +Cc: Ocaml

On Tue, Apr 01, 2003 at 07:34:24PM +0200, Alessandro Baretta wrote:

> Why are "match-anything" functions of the kind of
> 
> let f = function
>   | `Foo -> "foo"
>   | `Bar -> "bar"
>   | _ -> "?"
> 
> incompatible with signatures like
> 
> val f : [> `Foo ] -> string
> ?
> 
> There clearly is no case when a value of type [> `Foo] will 
> not be acceptable for f. So why does the type checker reject 
> this?

I would apply the same question to the object system: why can a
signature not hide methods of a class.

Does making the signature more restrictive somehow hurt the type system?

e.g.:

  class foo : object method baz : int end =
    object
      method baz = 5
      method bar = 2
    end

gives:

  The class type object method bar : int method baz : int end
  is not matched by the class type object method baz : int end
  The public method bar cannot be hidden

It seems to me this is the same kind of thing where struct's can contain
definitions that are not in the signature, and that can be used to hide
them.

Is there some underlying reason that I'm missing?  Perhaps assumptions
the type system makes about the signature being complete?

Dave Brown

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Typing problem with polymorphic variants
  2003-04-01 18:44 ` David Brown
@ 2003-04-02  1:34   ` Jacques Garrigue
  0 siblings, 0 replies; 5+ messages in thread
From: Jacques Garrigue @ 2003-04-02  1:34 UTC (permalink / raw)
  To: caml-list; +Cc: caml-list

From: David Brown <caml-list@davidb.org>

> I would apply the same question to the object system: why can a
> signature not hide methods of a class.
> 
> Does making the signature more restrictive somehow hurt the type system?
> 
> e.g.:
> 
>   class foo : object method baz : int end =
>     object
>       method baz = 5
>       method bar = 2
>     end
> 
> gives:
> 
>   The class type object method bar : int method baz : int end
>   is not matched by the class type object method baz : int end
>   The public method bar cannot be hidden


Just consider now a variant on your example:

  class foo : object method baz : int end =
    object (self)
      method baz = self#bar + 3
      method bar = 2
    end

  class bar = object
    inherit foo
    method bar = "hello"
  end

If you can forget the method bar, the class bar becomes typable.
However (new bar)#baz lead to computing ["hello" + 3] which is
unsound.

You can try to change the problem in many ways, but the conclusion is
that there is no way to allow the hiding of a public method without a
notion of generative types for objects or views. There is a paper by
Jerome Vouillon on the subject
  http://www.pps.jussieu.fr/~vouillon/publi.html
  Combining subsumption and binary methods: An object calculus with views.

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2003-04-02  1:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-01 17:34 [Caml-list] Typing problem with polymorphic variants Alessandro Baretta
2003-04-01 18:38 ` Ville-Pertti Keinonen
2003-04-01 17:56   ` Alessandro Baretta
2003-04-01 18:44 ` David Brown
2003-04-02  1:34   ` Jacques Garrigue

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