Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 如何解决反应性问题中的t矩类型问题?_Haskell_Reactive Programming_Frp_Reactive Banana - Fatal编程技术网

Haskell 如何解决反应性问题中的t矩类型问题?

Haskell 如何解决反应性问题中的t矩类型问题?,haskell,reactive-programming,frp,reactive-banana,Haskell,Reactive Programming,Frp,Reactive Banana,我试着写一个这样的函数: module Main where import Reactive.Banana import Reactive.Banana.Frameworks main = putStrLn "hello world" type MIDIMessage = (Int, Int, Double) startRBMidi f = do (addHandler, fire) <- newAddHandler :: IO (AddHandler MIDIMessa

我试着写一个这样的函数:

module Main where

import Reactive.Banana
import Reactive.Banana.Frameworks


main = putStrLn "hello world"

type MIDIMessage = (Int, Int, Double)

startRBMidi f = do
    (addHandler, fire) <- newAddHandler :: IO (AddHandler MIDIMessage, Handler MIDIMessage)
    let
        networkDesc = do
            emidi <- fromAddHandler (addHandler :: AddHandler MIDIMessage)
            f emidi
    network <- compile networkDesc
    actuate network
    -- add fire to midi callbacks
modulemain其中
进口香蕉
导入Reactive.Banana.Frameworks
main=putStrLn“你好,世界”
键入MIDIMessage=(Int,Int,Double)
startRBMidi f=do
(addHandler,火灾)力矩t1()
在测试时。hs:17:16-34
预期类型:力矩t1()
实际类型:力矩t()
相关绑定包括
networkDesc::矩t()(在test.hs:14:9处绑定)
f::Event t MIDIMessage->Moment t()(绑定在test.hs:11:13)
startRBMidi::(事件t MIDIMessage->矩t())->IO()
(在测试时绑定。hs:11:1)
在“compile”的第一个参数中,即“networkDesc”
在“do”块的stmt中:网络时刻t())->IO()
startRBMidi f=do
(addHandler,fire)IO()
startRBMidi f=do
(addHandler,火灾)力矩t()
networkDesc=do

emidi您需要为您的
startRBMidi
函数指定一个显式类型签名,因为它有一个rank-2类型:

startRBMidi :: (forall t. Event t MIDIMessage -> Moment t ()) -> IO ()
这与编译函数的类型类似


本质上,这意味着参数函数
f
需要在任何开始时间
t

工作。您还需要向
networkDesc
添加类型签名,因为否则,GHC将为本地
let
绑定推断单态类型签名,这不是您想要的。同样,
networkDesc
需要在所有开始时间都工作
t
。太好了,成功了!我必须说,对于不熟悉RANK2类型和幻影类型的人来说,要理解如何正确使用幻影参数t几乎是不可能的。对于那些不使用动态事件切换的人来说,拥有一个更简单版本的库是很有用的,尽管这会导致更多的工作和维护。谢谢你的帮助!很公平。由于这些问题,我打算离开类型参数
t
。看见
{-# LANGUAGE Rank2Types #-}
module Main where
import Reactive.Banana
import Reactive.Banana.Frameworks

main = putStrLn "hello world"

type MIDIMessage = (Int, Int, Double)

startRBMidi :: (forall t. Event t MIDIMessage -> Moment t ()) -> IO ()
startRBMidi f = do
    (addHandler, fire) <- newAddHandler :: IO (AddHandler MIDIMessage, Handler MIDIMessage)
    let
        networkDesc = do
            emidi <- fromAddHandler (addHandler :: AddHandler MIDIMessage)
            f emidi
    network <- compile networkDesc
    actuate network
test.hs:18:22:
No instance for (Frameworks t0)
  arising from a use of ‘fromAddHandler’
The type variable ‘t0’ is ambiguous
Relevant bindings include
  networkDesc :: Moment t0 () (bound at test.hs:17:9)
Note: there is a potential instance available:
  instance Frameworks
             (reactive-banana-0.8.0.4:Reactive.Banana.Internal.Phantom.FrameworksD,
              t)
    -- Defined in ‘reactive-banana-0.8.0.4:Reactive.Banana.Internal.Phantom’
In a stmt of a 'do' block:
  emidi <- fromAddHandler (addHandler :: AddHandler MIDIMessage)
In the expression:
  do { emidi <- fromAddHandler
                  (addHandler :: AddHandler MIDIMessage);
       f emidi }
In an equation for ‘networkDesc’:
    networkDesc
      = do { emidi <- fromAddHandler
                        (addHandler :: AddHandler MIDIMessage);
             f emidi }

test.hs:20:24:
Couldn't match type ‘t0’ with ‘t’
  because type variable ‘t’ would escape its scope
This (rigid, skolem) type variable is bound by
  a type expected by the context: Frameworks t => Moment t ()
  at test.hs:20:16-34
Expected type: Moment t ()
  Actual type: Moment t0 ()
Relevant bindings include
  networkDesc :: Moment t0 () (bound at test.hs:17:9)
In the first argument of ‘compile’, namely ‘networkDesc’
In a stmt of a 'do' block: network <- compile networkDesc
{-# LANGUAGE Rank2Types #-}
module Main where

import Reactive.Banana
import Reactive.Banana.Frameworks

main = putStrLn "hello world"

type MIDIMessage = (Int, Int, Double)

startRBMidi :: (forall t. Event t MIDIMessage -> Moment t ()) -> IO ()
startRBMidi f = do
    (addHandler, fire) <- newAddHandler :: IO (AddHandler MIDIMessage, Handler MIDIMessage)
    let
        networkDesc :: forall t. Frameworks t => Moment t ()
        networkDesc = do
            emidi <- fromAddHandler (addHandler :: AddHandler MIDIMessage)
            f emidi
    network <- compile networkDesc
    actuate network
startRBMidi :: (forall t. Event t MIDIMessage -> Moment t ()) -> IO ()