我有以下文件:
module SimpleComposition where
class Intermediate a where
f :: a -> Int
g :: Char -> a
h :: Char -> Int
h = f . g
Run Code Online (Sandbox Code Playgroud)
尝试在 ghci 中加载它时,出现错误:
main.hs:8:5: error:
* No instance for (Intermediate a0) arising from a use of `f'
* In the first argument of `(.)', namely `f'
In the expression: f . g
In an equation for `h': h = f . g
|
8 | h = f . g
| ^ …Run Code Online (Sandbox Code Playgroud) 我有以下文件:
module SimpleComposition where
class Domain a where
f :: a -> a
g :: a -> a
h = f . g
Run Code Online (Sandbox Code Playgroud)
尝试在 ghci 中加载它时,出现错误
src\play.hs:7:5: error:
* No instance for (Domain c0) arising from a use of `f'
* In the first argument of `(.)', namely `f'
In the expression: f . g
In an equation for `h': h = f . g
Run Code Online (Sandbox Code Playgroud)
我认为问题在于fand的类型gisforall a. Domain a => a ->a而不仅仅是a -> …