Browse thread
[Caml-list] Typing problem with polymorphic variants
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | David Brown <caml-list@d...> |
| Subject: | Re: [Caml-list] Typing problem with polymorphic variants |
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