Haskell Unable to infer (t ~ t1) out of context (Frameworks t)
I am learning how to use the Haskell FRP library called Reactive Banana, which is also fairly new to Haskell in general. I am currently creating a function that will take the network as a parameter, and in the body of the function does some initialization before compiling the network and going through its event loop, but I am having problems that Haskell cannot figure out what I am trying to do.
Here's the given version of the code
{-# 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 ()
The exact error I am getting is this.
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
A search on the internet leads me to think that the types between the framework in the launch function and the framework in the setupNetwork function are not considered the same.
Is there a way for the types to match?
source to share
It's been a while since I played with the reactive banana (or whatever pushes the type system so hard), but I think the type signature should be something more like
start :: (forall t. RF.Frameworks t => R.Moment t ()) -> IO ()
(i.e. you need to add parentheses where you want.)
You will need {-# LANGUAGE RankNTypes #-}
.
source to share