我有一个简短的例子:
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ImpredicativeTypes #-}
main = mapM_ print ([1 :: Int, "str", Just 5] :: [forall a. Show a => a])
这有两个原因失败(产生4个错误,但每个元素中有3个错误):
No instance for (Show (forall a. Show a => a))
arising from a use of `print'
这是非常令人费解的(我也不理解),另一个:
Could not deduce (a ~ Int)
from the context (Show a)
bound by a type expected by the context: Show a => a
at main.cpp:5:18-42
`a' is a rigid type variable bound by
a type expected by the context: Show a => a at main.cpp:5:18
In the expression: 1 :: Int
这似乎将上下文强化为Show a => a
。为什么它不起作用? Aren的impredicative类型基本上是这个的门户吗?