1

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.

  • 3
    From the type error, the t in Behavior t (AgentMap -> AgentMap) is different than the t in eTick's type. The most likely cause is that one of your definitions is more polymorphic than it should be. Perhaps you've defined something using let? You can try turning on scoped type variables and adding explicit types to force the ts to be the same. – Jason Dagit Jun 15 '13 at 20:05
  • 2
    Could you add code for `bHyperMap` and `bPlanetMap` – Ankur Jun 16 '13 at 07:47
  • 1
    As Jason said, your reasoning is mostly correct, but the type error is due to the type parameter `t` being different for `bHyperMap` and `eTick`. You need to post a larger code sample and show the context in which `eTick` and `bAgentMap` and `bHyperMap` are defined to resolve this. – Heinrich Apfelmus Jun 19 '13 at 10:06
  • Thanks for the responses. More code being posted later today. Work has been rather involved these past few days. –  Jun 19 '13 at 17:00

0 Answers0