gpt4 book ai didi

Haskell 无法从上下文中推导出 (t ~ t1) (框架 t)

转载 作者:行者123 更新时间:2023-12-02 15:53:37 26 4
gpt4 key购买 nike

我正在学习如何使用名为 Reactive Banana 的 Haskell FRP 库,并且总体上对 Haskell 来说还相当陌生。目前我正在创建一个函数,该函数将网络作为参数,并在函数体中在编译网络并经历其事件循环之前进行一些初始化,但我遇到了 Haskell 无法推断出我想要的问题做。

这是代码的简化版本

{-# LANGUAGE ScopedTypeVariables #-}

module Main where
import qualified Reactive.Banana as R
import qualified Reactive.Banana.Frameworks as RF

main = start setupNetwork

start :: forall t. RF.Frameworks t => R.Moment t () -> IO ()
start network = do
net <- RF.compile $ network
RF.actuate net

keyAddHandler = RF.newAddHandler

setupNetwork :: forall t. RF.Frameworks t => R.Moment t ()
setupNetwork = do
(addKey, firekey) <- RF.liftIO keyAddHandler
return ()

我收到的确切错误是这样的。

Test.hs:11:25:
Could not deduce (t ~ t1)
from the context (RF.Frameworks t)
bound by the type signature for
start :: RF.Frameworks t => R.Moment t () -> IO ()
at Test.hs:(10,1)-(12,18)
or from (RF.Frameworks t1)
bound by a type expected by the context:
RF.Frameworks t1 => R.Moment t1 ()
at Test.hs:11:12-31
`t' is a rigid type variable bound by
the type signature for
start :: RF.Frameworks t => R.Moment t () -> IO ()
at Test.hs:10:1
`t1' is a rigid type variable bound by
a type expected by the context: RF.Frameworks t1 => R.Moment t1 ()
at Test.hs:11:12
Expected type: R.Moment t1 ()
Actual type: R.Moment t ()
In the second argument of `($)', namely `network'
In a stmt of a 'do' block: net <- RF.compile $ network

通过互联网搜索,我认为 start 函数中的框架和 setupNetwork 函数中的框架之间的类型不被视为同一类型。

有没有办法让类型匹配?

最佳答案

我已经有一段时间没有使用reactive-banana(或者其他任何插入类型系统发展的东西了),但我认为类型签名应该更像是这样的

start :: (forall t. RF.Frameworks t =>  R.Moment t ()) -> IO ()

(即您需要在正确的位置添加括号。)

您还需要{-# LANGUAGE RankNTypes #-}

关于Haskell 无法从上下文中推导出 (t ~ t1) (框架 t),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14657811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com