I'm getting the following error:
Libraries/Reactive/GameMechanic.hs:34:80:
No instance for (Apply (Behavior t0) (Event t))
arising from a use of `<@'
Possible fix:
add an instance declaration for (Apply (Behavior t0) (Event t))
In the second argument of `($)', namely
`(updateAgentMap <$> bHyperMap <*> bPlanetMap) <@ eTick'
In the expression:
accumB initialAMap
$ (updateAgentMap <$> bHyperMap <*> bPlanetMap) <@ eTick
In an equation for `bAgentMap':
bAgentMap
= accumB initialAMap
$ (updateAgentMap <$> bHyperMap <*> bPlanetMap) <@ eTick
The t0
in the Event
and the t1
in the Behavior
is my clue as to the problem, but I don't know how to interpret this clue. So let's start with some types, the errant code and my reasoning as to why it should work.
bAgentMap :: Behavior t AgentMap
bAgentMap = accumB initialAMap $ (updateAgentMap <$> bHyperMap <*> bPlanetMap) <@ eTick
initialAMap :: AgentMap
updateAgentMap :: HyperMap -> PlanetMap -> AgentMap -> AgentMap
bHyperMap :: Behavior t HyperMap
bPlanetMap :: Behavior t PlanetMap
accumB :: a -> Event t (a -> a) -> Behavior t a
So I've got the first parameter covered, AgentMap
. The second one needs to be Event t (AgentMap -> AgentMap)
. How to get there? If I begin with updateAgentMap <$> bHyperMap
, the type should be Behavior t (PlanetMap -> AgentMap -> AgentMap)
. Okay one more parameter updateAgentMap <$> bHyperMap <*> bPlanetMap
gives us a type Behavior t (AgentMap -> AgentMap)
. Almost there right?
Given this
(<@) :: f a -> g b -> g a
and
eTick :: Event t ()
and substituting a
for (AgentMap -> AgentMap)
I should be able to do this
(updateAgentMap <$> bHyperMap <*> bPlanetMap)
<@ eTick
to get Event t (AgentMap -> AgentMap)
But not so fast. My reasoning must be failing somewhere. Could someone tell me where?
Update: It turns out this problem occurred because eTick was not defined (I think). I had attempted to separate much of the code out into it's own file. I knew leaving eTick undefined
wouldn't be satisfactory, but I haven't worked out what I want to do about this. So in the meantime I started moving code into a let binding as I originally had. Now my code compiles. I don't want the let
bindings to stay there for long. My expectation is that a revisit to the breakout project will show me how to better structure my code.