我試圖在ghci
控制檯中做最簡單的事情。我希望能夠擁有類型[Maybe Int]
的值。但無論Nothing : [1, Nothing]
或[1, Nothing] ++ [Nothing]
給人,我覺得很難理解的錯誤:由於使用'it'而導致的(Num(也許a0))的實例
No instance for (Num (Maybe a0)) arising from a use of ‘it’
In the first argument of ‘print’, namely ‘it’
In a stmt of an interactive GHCi command: print it
請能有人解釋這個錯誤,並提出如何解決它?
'[1,沒什麼]'?在Haskell中,列表只包含一種元素。 –
我想能夠擁有'[Maybe Int]'類型的值。我必須明確指定它嗎? – altern
您需要在'Just'構造函數中包裝'1'('只有1')。'Nothing'與其他語言中的'null'不同,它只是'Maybe'的空構造函數。 – ryachza