我是 Haskell 的新手。我有以下类型:
type Variable = String
type Value = Float
type EvalError = [Variable]
type EvalResult = Either EvalError Value
我想创建一个函数,我将使用一个函数在 2EvalResult
种类型上使用它,并相应地得到一个EvalResult
。如果我得到 2 个值类型,我想对它们使用函数(例如 sum/sub),如果我得到 EvalError,我想返回 EvalError。
我做了什么:
evalResultOp :: (a -> b -> c) -> EvalResult a -> EvalResult b -> EvalResult c
evalResultOp f (Left a) (Left b) = Left (a ++ b)
evalResultOp f (Left a) (Right b) = Left a
evalResultOp f (Right a) (Left b) = Left b
evalResultOp f (Right a) (Right b) = Right (f a b)
错误:
hs3.hs:46:34: error:
• Expecting one fewer arguments to ‘EvalResult’
Expected kind ‘* -> *’, but ‘EvalResult’ has kind ‘*’
• In the type signature:
evalResultOp :: (a -> b -> c)
-> EvalResult a -> EvalResult b -> EvalResult c
|
46 | evalResultOp :: (a -> b -> c) -> EvalResult a -> EvalResult b -> EvalResult c | ^^^^^^^^^^^^
hs3.hs:46:50: error:
• Expecting one fewer arguments to ‘EvalResult’
Expected kind ‘* -> *’, but ‘EvalResult’ has kind ‘*’
• In the type signature:
evalResultOp :: (a -> b -> c)
-> EvalResult a -> EvalResult b -> EvalResult c
|
46 | evalResultOp :: (a -> b -> c) -> EvalResult a -> EvalResult b -> EvalResult c | ^^^^^^^^^^^^
hs3.hs:46:66: error:
• Expecting one fewer arguments to ‘EvalResult’
Expected kind ‘* -> *’, but ‘EvalResult’ has kind ‘*’
• In the type signature:
evalResultOp :: (a -> b -> c)
-> EvalResult a -> EvalResult b -> EvalResult c
|
46 | evalResultOp :: (a -> b -> c) -> EvalResult a -> EvalResult b -> EvalResult c |