Browse thread
polymorphic variants and promotion
-
Johannes Kanig
- Julien Signoles
-
Remi Vanicat
- Jacques Garrigue
[
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: | Jacques Garrigue <garrigue@m...> |
| Subject: | Re: [Caml-list] Re: polymorphic variants and promotion |
From: Remi Vanicat <vanicat@debian.org> > Well, you have to explicitly coerce : > > let h a = function > | [] -> g a > | xs -> (List.fold_left f a xs : [ `A of _ ] :> [> `A of _ | `B of _ ]) ;; > > What I don't understand is why this : > > let h a = function > | [] -> g a > | xs -> (List.fold_left f a xs :> [> `A of _ | `B of _ ]) ;; > > do not work ? I understood that we need to explicitly coerce, but the > [ `A of _ ] is just the information the compiler will find by itself, > why must we give it to it again ? Because we cannot always be sure that the compiler will infer it at the right time. I.e., we would end up with some programs having different typing behaviours when the above application is inferred as [`A of _] and when a less precise type is inferred, which could cause unification errors somewhere else... We are currently considering allowing the above kind of abbreviation when both the source and target are ground types (i.e. do not contain type variables). But this would not include the above example. Jacques Garrigue