2014-04-12 10 views
102

Güncel davranış

Prelude> show _ 

<interactive>:7:6: 
    Found hole ‘_’ with type: a0 
    Where: ‘a0’ is an ambiguous type variable 
    Relevant bindings include it :: String (bound at <interactive>:7:1) 
    In the first argument of ‘show’, namely ‘_’ 
    In the expression: show _ 
    In an equation for ‘it’: it = show _ 

İstenilen davranış

GHC da daktilo delik Show tipi sınıf kısıtlaması vardır söyle olsaydı iyi olurdu.GHC, yazılan deliklerin tip sınıfı kısıtlamalarını sağlamanın bir yolu var mı?

Çeşitli

GHC Versiyon 7.8.1

+16

afaik ama kesinlikle olur: Eğer ghc ile derlemek ya da (:set -XNoExtendedDefaultRules aracılığıyla) GHCi uzatıldı varsayılan kuralları devre dışı bırakırsanız

Yine de, biz iyileştirmeler sonucunu görmek Bir işe yara. Bunun için GHC hata izleyicisinde bir özellik talebi açmaya değer olabilir. – kosmikus

+11

Bunun faydalı olacağını kabul ediyorum. Bunu GHC trac'sinde bir özellik isteği olarak bildirdim: https://ghc.haskell.org/trac/ghc/ticket/9479 –

+4

Şimdilik, ön-tipi-deliklerini kullanabilirsiniz: 'show (undefined ::() ->()) '; GHC, daha fazla tip kontrol hatası verir. – phadej

cevap

1

Resim şu anda bu spekülasyonlar göre ghc ilave edilebilir possible.But değildir.

2

Bu, @ DominiqueDevriese'nin GHC ticket sayesinde GHC 8.0'da düzeltildi.

extended type defaulting nedeniyle, bu GHCi'de hemen belli olmaz. senin örnek ile deliğin

> 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) 

tip () öndeğer olarak alır. Görünüşe göre desired behavior, genişletilmiş varsayılanların delikler için geçerli olmaması gerektiğine dair bir argüman olsa da (bunlar için ortak bir kullanım olarak derleyicinin türden türünü size bildirmesi gerekir). Bu, mümkün anda değil

<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)