summaryrefslogtreecommitdiff
path: root/testsuite/tests/boxy/Base1.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2016-09-25 15:50:18 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2016-09-30 12:53:27 +0100
commitb612da667fe8fa5277fc78e972a86d4b35f98364 (patch)
tree814c66b0dfb9e218d25f21f1d84617088c151987 /testsuite/tests/boxy/Base1.hs
parent3012c431e466c55fccff0dd916987a9478cb1ae3 (diff)
downloadhaskell-b612da667fe8fa5277fc78e972a86d4b35f98364.tar.gz
Fix impredicativity (again)
This patch fixes Trac #12616. Dignosis. In TcUnify.tc_sub_type_ds we were going to some trouble to support co- and contra-variance even for impredicative types. With -XImpredicativeTYpes, this allowed a unification variable to be unified with a polytype (probably wrongly) and that caused later trouble in the constraint solver, where -XImpredicativeTypes was /not/ on. In effect, -XImpredicativeTypes can't be switched on locally. Why did we want ImpredicativeTypes locally? Because the program generated by GND for a higher-rank method involved impredicative instantation of 'coerce': op = coerce op -- where op has a higher rank type See Note [Newtype-deriving instances] in TcGenDeriv. Cure. 1. It is ghastly to rely on ImpredicativeTypes (a 100% flaky feature) to instantiate coerce polymorphically. Happily we now have Visible Type Application, so I've used that instead which should be solid and reliable. 2. I deleted the code in tc_sub_type_ds that allows the constraint solver to "look through" a unification variable to find a polytype. That used to be essential in the days of ReturnTv, but it's utterly unreliable and should be consigned to the dustbin of history. (We have ExpType now for the essential uses.) Tests involving ImpredicativeTypes are affected, but I'm not worried about them... it's advertised as a feature you can't rely on, and I want to reform it outright.
Diffstat (limited to 'testsuite/tests/boxy/Base1.hs')
-rw-r--r--testsuite/tests/boxy/Base1.hs35
1 files changed, 19 insertions, 16 deletions
diff --git a/testsuite/tests/boxy/Base1.hs b/testsuite/tests/boxy/Base1.hs
index 88e7e80f17..3f027bb93c 100644
--- a/testsuite/tests/boxy/Base1.hs
+++ b/testsuite/tests/boxy/Base1.hs
@@ -1,30 +1,33 @@
{-# OPTIONS_GHC -XImpredicativeTypes -fno-warn-deprecated-flags #-}
-module Base1 where
--- basic examples of impredicative instantiation of variables
+-- Sept 16: now failing, beause I've furter reduced the scop
+-- of impredicative types
-data MEither a b = MLeft a
- | MRight b
+module Base1 where
+-- basic examples of impredicative instantiation of variables
+
+data MEither a b = MLeft a
+ | MRight b
| MEmpty
-type Sid = forall a. a -> a
+type Sid = forall a. a -> a
--- no need for impredicativity
-test0 = MRight id
+-- no need for impredicativity
+test0 = MRight id
--- requires impredicativity
+-- requires impredicativity
test1 :: Sid -> MEither Sid b
-test1 fid = MLeft fid
+test1 fid = MLeft fid
-test2 :: MEither b Sid -> Maybe (Sid,Sid)
-test2 m = case (test1 id) of
- MLeft x -> case m of
- MRight y -> Just (x,y)
- _ -> Nothing
+test2 :: MEither b Sid -> Maybe (Sid,Sid)
+test2 m = case (test1 id) of
+ MLeft x -> case m of
+ MRight y -> Just (x,y)
+ _ -> Nothing
_ -> Nothing
test3 :: MEither a b -> b
-test3 (MRight x) = x
+test3 (MRight x) = x
-test4 = test3 (test1 id)
+test4 = test3 (test1 id)