3

我正在学习如何使用名为 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 函数中的框架之间的类型不被认为是同一类型。

反正有没有让类型匹配?

4

1 回答 1

3

自从我玩过响应式香蕉(或其他任何推动类型系统的东西)以来已经有一段时间了,但我认为类型签名应该更像

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

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

{-# LANGUAGE RankNTypes #-}也需要。

于 2013-02-02T08:26:06.310 回答