有人可以向我解释为什么这个(版本 1)可以编译,而下面的版本(版本 2)没有。
-- version 1 (compiles)
module Chapter2 where
import Debug.Trace
data Wrapper a = Wrapper a
instance showWrapper :: (Show a) => Show (Wrapper a) where
show (Wrapper w) = "Wrapper ( " ++ (show w) ++ " )"
foo :: Number -> Number -> Number -> Number
foo a b c = a + b + c
foo1 = foo 2
foo2 = foo 1 2
class ExecFn a where
exec :: a -> Number
instance execFn1 :: ExecFn (Number -> Number -> Number) where
exec a = 99
main = do
let x = exec foo1
trace "Hello"
这不编译
-- Version 2 (does not compile)
module Chapter2 where
import Debug.Trace
data Wrapper a = Wrapper a
instance showWrapper :: (Show a) => Show (Wrapper a) where
show (Wrapper w) = "Wrapper ( " ++ (show w) ++ " )"
foo :: Number -> Number -> Number -> Number
foo a b c = a + b + c
foo1 = foo 2
foo2 = foo 1 2
class ExecFn a b where
exec :: a -> Wrapper b
instance execFn1 :: ExecFn (Number -> Number -> Number) Number where
exec a = Wrapper 99
main = do
let x = exec foo1
trace "Hello"
并给我这个错误
Error at src/Chapter2.purs line 3, column 1 - line 5, column 1:
No instance found for Chapter2.ExecFn (Prim.Number -> Prim.Number -> Prim.Number) u8735
那么如何制作类似于我的版本 2 的版本,以便我可以将我的结果放入包装器中?