Ответ 1
Теперь это исправлено в GHC 8.0 благодаря @DominiqueDevriese билет GHC.
Из-за расширенного типа по умолчанию, это не сразу видно в GHCi. В вашем примере
> show _
<interactive>:7:6: error:
• Found hole: _h :: ()
Or perhaps ‘_h’ is mis-spelled, or not in scope
• In the first argument of ‘show’, namely ‘_h’
In the expression: show _h
In an equation for ‘it’: it = show _h
• Relevant bindings include
it :: String (bound at <interactive>:7:1)
тип отверстия по умолчанию равен ()
. Это, по-видимому, желаемое поведение, хотя есть аргумент, который должен быть сделан, что расширенное дефолт не должно относиться к отверстиям (поскольку их обычное использование чтобы заставить компилятор рассказать вам о выведенном типе).
Тем не менее, если вы скомпилируете GHC или отключите расширенные правила по умолчанию в GHCi (через :set -XNoExtendedDefaultRules
), мы увидим результат улучшений:
<interactive>:3:1: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘show’
prevents the constraint ‘(Show a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show Integer -- Defined in ‘GHC.Show’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
...plus 22 others
...plus 11 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: show _
In an equation for ‘it’: it = show _
<interactive>:3:6: error:
• Found hole: _ :: a0
Where: ‘a0’ is an ambiguous type variable
• In the first argument of ‘show’, namely ‘_’
In the expression: show _
In an equation for ‘it’: it = show _
• Relevant bindings include
it :: String (bound at <interactive>:3:1)