1 {-# OPTIONS -fglasgow-exts #-}
4 From: Ralf Hinze <ralf@uran.informatik.uni-bonn.de>
5 Date: Fri, 15 Aug 1997 15:20:51 +0200 (MET DST)
7 I *suppose* that there is a bug in GHC's type checker. The following
8 program, which I think is ill-typed, passes silently the type checker.
9 Needless to say that it uses some of GHC's arcane type extensions.
12 module ShouldFail where
14 import GlaExts ( All )
16 data ContT m a = KContT ((All res) => (a -> m res) -> m res)
17 unKContT (KContT x) = x
19 callcc :: ((a -> ContT m b) -> ContT m a) -> ContT m a
20 callcc f = KContT (\cont -> unKContT (f (\a -> KContT (\cont' -> cont a))) cont)
23 `ContT' is a continuation monad transformer. Note that we locally
24 qualify over the result type `res' (sometimes called answer or
25 output). IMHO this make it impossible to define control constructs
26 like `callcc'. Let's have a closer look: the code of `callcc' contains
27 the subexpression `KContT (\cont' -> cont a)'. To be well-typed the
28 argument of `KContT' must have the type `(All res) => (a -> m res) -> m
29 res'. Quantification is not possible, however, since the type variable
30 in `cont's type cannot be forall'd, since it also appears at an outer
31 level. Right? Or wrong?