I am working on a library to study theoretical teaching of the game. In this setup, N agents combine and interact with the environment. Each agent receives an interaction model. The single agent model depends on his opponents N-1 . I wrote code defining this model for agents 1 agent and 2 , and am trying to generalize it. Here is the part of the code that I have:
data System wxashh' = System { signaling :: SignalingWXAS wxas , dynamic :: DynamicXAS xas , strategy :: MockupStrategy xashh' } data JointState wxashh' = JointState { worldState :: w , state :: x , mockupState :: MockupState ashh' } systemToMockup :: ( Bounded w, Ix w, Bounded x, Ix x , Bounded a, Ix a, Bounded s, Ix s , Bounded (ha), Ix (ha), Bounded (h' s), Ix (h' s) , History h, History h' ) => System wxashh' -> Mockup ashh' systemToMockup syst = mock where mock z = norm $ statDist >>=? condit z >>= computeStatesAndAction >>= sig >>=$ extractSignal statDist = ergodicStationary $ transition syst condit z = just z . mockupState sig = uncurryN $ signaling syst strat = strategy syst computeStatesAndAction joint = do let w = worldState joint let x = state joint a <- strat x (mockupState joint) return (w, x, a) extractSignal (_, s) = s
and
data System2 w x1 a1 s1 h1 h1' x2 a2 s2 h2 h2' = System2 { signaling :: SignalingWXAS2 w x1 a1 s1 x2 a2 s2 , dynamic1 :: DynamicXAS x1 a1 s1 , dynamic2 :: DynamicXAS x2 a2 s2 , strategy1 :: MockupStrategy x1 a1 s1 h1 h1' , strategy2 :: MockupStrategy x2 a2 s2 h2 h2' } data JointState2 w x1 a1 s1 h1 h1' x2 a2 s2 h2 h2' = JointState2 { worldState :: w , state1 :: x1 , mockupState1 :: MockupState a1 s1 h1 h1' , state2 :: x2 , mockupState2 :: MockupState a2 s2 h2 h2' } systemToMockups2 syst = (mock1, mock2) where mock1 z1 = norm $ statDist >>=? condit1 z1 >>= computeStatesAndActions >>= sig >>=$ extractSignal1 mock2 z2 = norm $ statDist >>=? condit2 z2 >>= computeStatesAndActions >>= sig >>=$ extractSignal2 statDist = ergodicStationary $ transition2 syst condit1 z1 = just z1 . mockupState1 condit2 z2 = just z2 . mockupState2 sig = uncurryN $ signaling syst strat1 = strategy1 syst strat2 = strategy2 syst computeStatesAndActions joint = do let w = worldState joint let x1 = state1 joint let x2 = state2 joint a1 <- strat1 x1 (mockupState1 joint) a2 <- strat2 x2 (mockupState2 joint) return (w, x1, a1, x2, a2) extractSignal1 (_, s, _) = s extractSignal2 (_, _, s) = s
I am after defining a function for systemToMockupN , which can accommodate any finite number of agents.
Agents are heterogeneous, so using lists is not possible. I canât use tuples because I donât know the size in advance. I tried using curryN , uncurryN , etc., but could not perform one operation for each element of the tuple. I tried to create a variational function like printf without success.
I know that I can use the haskell template, but I am wondering if there is a nicer solution that I am missing. Any pointer to some code dealing with a finite but arbitrary number of heterogeneous elements would be greatly appreciated.