Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Auto-closing polymorphic variants ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-02-21 (12:21)
From: David Teller <David.Teller@u...>
Subject: Re: [Caml-list] Auto-closing polymorphic variants ?
On Thu, 2008-02-21 at 10:54 +0900, Jacques Garrigue wrote:
> This does not mean that we can try nothing. For instance we could
> introduce a warning when a pattern matching adds a new tag to a
> polymorphic input. The idea is that since the input is polymorphic, it
> is sure that it will never actually contain extra tags.
> And thanks to the relaxed value restriction, the result of safe_div
> would be just polymorphic enough to trigger the warning, while example
> like the above, by being not polymorphic, would not trigger it.
> But this would not be easy to implement...

Sounds like a good idea. How hard would that be ?

> > Of course, we could do that by manually closing the type of safe_div,
> > but this would essentially mean duplicating information.
> > 

> It is better to either define safe_div as returning a closed variant
> type (writing interfaces in ocaml _is not_ code duplication, it is
> code specification!) or not use wild cards in pattern matchings
> on open polymorphic variants.

I agree that, whenever module barriers are crossed, interfaces become
specifications. However, as soon as you're remaining inside one module,
it's nice to be more lightweight and just let inference handle
everything. This is where a warning (or something like a "close"
operator) would come in handy.

David Teller
 Security of Distributed Systems
 Angry researcher: French Universities need reforms, but the LRU act brings liquidations.