我做了以下haskell程序,它將執行一些基本的加載,讀取和增量操作。我收到一個類型錯誤。有人可以告訴爲什麼類型錯誤在那裏,我該如何解決它。haskell程序中的錯誤
module ExampleProblem (Value,read',load,incr) where
newtype Value a = Value Int deriving (Eq,Read,Show)
read':: Value Int -> Int
read' (Value a) = a
load:: Int -> Value Int
load a = Value a
incr:: Value Int -> Value Int
incr (Value a) = Value (a+1)
main = do
(Value ab) <- (load 42)
if (read'(Value ab) /= 42)
then show "Failure to load"
else do
Value b <- incr(Value ab)
Value c <- incr(Value b)
if ((Value c) == Value 44)
then show "Example finished"
else show "error"
return
我得到的錯誤是:
Couldn't match expected type `Int' with actual type `Value t0'
In the pattern: Value ab
In a stmt of a 'do' expression: (Value ab) <- (load 42)
In the expression:
do { (Value ab) <- (load 42);
if (read' (Value ab) /= 42) then
show "Failure to load"
else
do { Value b <- incr (Value ab);
.... } }
當我做在我寫的主要功能我漸漸的範圍誤差雖然我是導入模塊ExampleProblem一個單獨的文件。
Not in scope: data constructor `Value'
5個問題,並沒有接受答案。請工作。 – leppie
對不起,我不知道它..已經做了修改:) –