[bitc-dev] Haskell question: exceptions

Iavor Diatchki iavor.diatchki at gmail.com
Fri Aug 12 14:29:49 EDT 2005


Hello,
I think that you are running into the value restriction, and the
problem is independent of exceptions.  Here is an example of the same
behavior without exceptions:

# let rec undef x = undef x;;
val undef : 'a -> 'b = <fun>
#  let neg x = 1;;
val neg : 'a -> int = <fun>
# let test = if true then neg else undef 1;;
val test : '_a -> int = <fun>

I think the original ML value restriction said that only expressions
that syntactically look like values can be polymorphic.  Then it is
surprising that the following works:

# let r = if true then [] else raise Xn;;
val r : 'a list = []

because the expression is not a value, and yet it became polymorphic. 
What happened is that at some point in ocaml they relaxed the value
restriction to make it more permisive.  I think the details of the new
value restriction can be found in the paper "Relaxing The Value
Restriction" by Jacques Garrigue.  I have not read the paper, but
there is a brief explanation of the changes here:
http://sardes.inrialpes.fr/~aschmitt/cwn/2003.09.16.html#1
                                                 
-Iavor

On 8/11/05, Jonathan S. Shapiro <shap at eros-os.org> wrote:
> On Thu, 2005-08-11 at 23:02 -0400, Swaroop Sridhar wrote:
> > # exception Xn;;
> > exception Xn
> >
> > # let p = if true then id else id;;
> > val p : 'a -> 'a = <fun>
> >
> > # let q = if true then id else raise Xn;;
> > val q : '_a -> '_a = <fun>
> 
> I believe that it is the second case that we find puzzling.
> 
> _______________________________________________
> bitc-dev mailing list
> bitc-dev at coyotos.org
> http://www.coyotos.org/mailman/listinfo/bitc-dev
>



More information about the bitc-dev mailing list