为什么应用能力处理程序有时无法免除能力要求?
使用以下代码:
runGeneration :
([BasePair] -> Float)
-> ([EntityFitness] ->{Random} [EntityFitness])
-> [EntityFitness]
->{Random, Remote} [EntityFitness]
runGeneration = iterateGenDefault 0.8 0.5
bar = Remote.pure.run 'runGeneration
UCM显示以下签名:
⍟ These new definitions are ok to `add`:
bar : Either
Failure
(([BasePair] -> Float)
-> ([EntityFitness] ->{Random} [EntityFitness])
-> [EntityFitness]
->{g, Remote, Random} [EntityFitness])
⍟ These names already exist. You can `update` them to your new definition:
runGeneration : ([BasePair] -> Float)
-> ([EntityFitness] ->{Random} [EntityFitness])
-> [EntityFitness]
->{Remote, Random} [EntityFitness]
我不理解的部分是bar
的签名,其签名中仍然具有远程
。是否应该通过调用处理程序remote.pure.run
来免除这?
我觉得这与我做愚蠢的事情有关,例如将能力要求放在签名的错误位置。
对于使用随机的更简单的示例,随机
要求已免除:
randFooH : Nat ->{Random} Nat
randFooH max = Random.natIn 1 max
randFoo max = Random.splitmix 1234 '(randFooH max)
⍟ These new definitions are ok to `add`:
randFoo : Nat -> Nat
randFooH : Nat ->{Random} Nat
好的,因此检查问题是否仅与远程
一起,看来情况并非如此,情况并非如此,由于这个(独立的)示例也是绝对的:
forkHelloH: '{Remote} Nat
forkHelloH = 'let
use Nat +
use Remote await forkAt here!
t1 = forkAt here! '(1 + 1)
t2 = forkAt here! '(2 + 2)
await t1 + await t2
forkHello = Remote.pure.run forkHelloH
⍟ These new definitions are ok to `add`:
forkHello : Either Failure Nat
forkHelloH : '{Remote} Nat
更新和澄清
我最初是在尝试这种能力的部分应用以调试问题 - 解决此问题的更好方法是应用程序能力处理人员尽可能迟到。我的问题与实施了某些没有能力 - 多态性的功能有关(请参见下面的答案中的评论)。
With the following code:
runGeneration :
([BasePair] -> Float)
-> ([EntityFitness] ->{Random} [EntityFitness])
-> [EntityFitness]
->{Random, Remote} [EntityFitness]
runGeneration = iterateGenDefault 0.8 0.5
bar = Remote.pure.run 'runGeneration
UCM shows these signatures:
⍟ These new definitions are ok to `add`:
bar : Either
Failure
(([BasePair] -> Float)
-> ([EntityFitness] ->{Random} [EntityFitness])
-> [EntityFitness]
->{g, Remote, Random} [EntityFitness])
⍟ These names already exist. You can `update` them to your new definition:
runGeneration : ([BasePair] -> Float)
-> ([EntityFitness] ->{Random} [EntityFitness])
-> [EntityFitness]
->{Remote, Random} [EntityFitness]
The part I'm not understanding is the signature of bar
, which still has Remote
in its signature. Shouldn't this be absolved by invoking the handler Remote.pure.run
?
I have a feeling this is related to my doing something silly, like putting an ability requirement in the wrong place of a signature.
For a simpler example using Random, the Random
requirement is absolved:
randFooH : Nat ->{Random} Nat
randFooH max = Random.natIn 1 max
randFoo max = Random.splitmix 1234 '(randFooH max)
⍟ These new definitions are ok to `add`:
randFoo : Nat -> Nat
randFooH : Nat ->{Random} Nat
OK, so checking to see if the issue is just with Remote
, it appears that this is not the case, as this (self-contained) example also absolves:
forkHelloH: '{Remote} Nat
forkHelloH = 'let
use Nat +
use Remote await forkAt here!
t1 = forkAt here! '(1 + 1)
t2 = forkAt here! '(2 + 2)
await t1 + await t2
forkHello = Remote.pure.run forkHelloH
⍟ These new definitions are ok to `add`:
forkHello : Either Failure Nat
forkHelloH : '{Remote} Nat
Update and clarification
I was originally trying this partial application of abilities in order to debug an issue - the better way to go about this is (usually) to apply the ability handlers as late as possible. My issue was related to having implemented some functions that weren't ability-polymorphic (see comments in answers below).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回应他人(嗨,嗨!
Echoing others (hi folks!????) + a note about combining those two abilities. I think the reason that
Remote
is showing up in the signature ofbar
is thatrunGeneration
isn't being invoked with its arguments.runGeneration
is a function which performs the remote ability when it's applied, so the signaturebar : Either Failure (([A] -> B) -> ([C] ->{Random} [C]) -> [C] ->{g, Remote, Random} [C])
is saying, "I can either return a Failure or a function which happens to perform the Remote ability," but until the calls to theRemote
ability are actually made, the ability handler can't really eliminate the ability.Here's a simplified example which allows
bar
to eliminate theRemote
ability requirement:Assuming you may have deferred calling
runGeneration
with its arguments because of theRandom
ability requirement, here's a tip on some complexity there:because we're performing the
Random
ability in concert withRemote
there's an order of operations for eliminating abilities.The signature for the
Remote.pure.run
handler is:'{Remote, Exception, Scratch} a -> Either Failure a
which has less ability variables than a common ability handler likeStream.toList : '{g, Stream a} r -> '{g} [a]
. The lack of the generic ability variable{g}
meanspure.run
can handle the three ability requirements indicated, but does not permit other abilities to be passed through and performed (for safety reasons,) so you'll want to eliminate yourRandom
ability before trying to interpret it with thepure.run
handler.我认为这是因为需要
远程
功能的功能实际上并未被评估/处理。处理程序仅消除表达式传递给它的最高节点的能力。为了消除它,您需要通过将其包裹在应用处理程序的东西(?)中来明确转换内部功能(?)
I think it's because the function that requires the
Remote
ability is not actually being evaluated/handled. The handler only eliminates abilities at the top node of the expression passed to it.To eliminate it you would need to transform the inner function explicitly by wrapping it in something that applies the handler (?)