相关疑难解决方法(0)

隐含的参数和功能

考虑Haskell(GHC)中的隐式参数,我遇到了问题.我有一个函数f,它假定隐含参数x,并希望通过将f应用于g来将其封装在上下文中

f :: (?x :: Int) => Int -> Int
f n = n + ?x

g :: (Int -> Int) -> (Int -> Int)
g t = let ?x = 5 in t
Run Code Online (Sandbox Code Playgroud)

但是当我试图评估时

g f 10
Run Code Online (Sandbox Code Playgroud)

我得到一个x没有绑定的错误,例如:

Unbound implicit parameter (?x::Int)
  arising from a use of `f'
In the first argument of `g', namely `f'
In the second argument of `($)', namely `g f 10'
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我,我做错了什么?

(我试图让Haskell的WordNet接口工作 - …

parameters haskell implicit ghc wordnet

9
推荐指数
2
解决办法
1640
查看次数

标签 统计

ghc ×1

haskell ×1

implicit ×1

parameters ×1

wordnet ×1