小编Sen*_*eno的帖子

在 Haskell 中组合具有中间多态类型的函数

我有以下文件:

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)

polymorphism haskell function-composition

2
推荐指数
1
解决办法
76
查看次数

如何在 Haskell 中组合多态函数?

我有以下文件:

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 -> …

polymorphism haskell composition

0
推荐指数
1
解决办法
64
查看次数