這是haskell代碼。我發現爲什麼我在下面錯了。在Haskell中打印空列表
main = do
print [1] -- Okay
print [] -- error
錯誤字符串如下。
P07.hs:38:11: error: ? Ambiguous type variable ‘t0’ arising from a use of ‘print’ prevents the constraint ‘(Show t0)’ from being solved. Probable fix: use a type annotation to specify what ‘t0’ 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 five instances involving out-of-scope types (use -fprint-potential-instances to see them all) ? In a stmt of a 'do' block: print [] In the expression: do { print [] } In an equation for ‘main’: main = do { print [] }
我試過[] :: Show
無法正常工作。我想我只是不知道錯誤是什麼意思..請幫助我。 謝謝。
請參閱[this](http://stackoverflow.com/a/23611674/382982)回答。 – pdoherty926