Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8573091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:10:19+00:00 2026-06-11T19:10:19+00:00

I am working on a library to study game theoretic learning. In this setting,

  • 0

I am working on a library to study game theoretic learning.
In this setting, N agents are brought together and interact with an environment.
Each agent derives a model of the interaction.
The model of one agent depends on its N-1 opponents.
I wrote the code determining that model for 1 agent and 2 agents, and am trying to generalize it. Here is part of the code I have:

data System w x a s h h' = System { signaling :: SignalingWXAS w x a s
                                  , dynamic   :: DynamicXAS x a s
                                  , strategy  :: MockupStrategy x a s h h' }

data JointState w x a s h h' = JointState { worldState  :: w
                                          , state       :: x
                                          , mockupState :: MockupState a s h h' }

systemToMockup :: ( Bounded w, Ix w, Bounded x, Ix x
                  , Bounded a, Ix a, Bounded s, Ix s
                  , Bounded (h a), Ix (h a), Bounded (h' s), Ix (h' s)
                  , History h, History h'
                  ) => System w x a s h h' -> Mockup a s h h'
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 a function definition for systemToMockupN that could accommodate any finite number of agents.

Agents are heterogenous so use of lists is not directly possible.
I cannot use tuples because I do not know the size in advance.
I tried using curryN, uncurryN, etc. but did not manage to do one operation on every element of a tuple.
I tried building a variadic function in a fashion similar to printf with no success.

I know I could use template haskell but I am wondering if there is a nicer solution I am overlooking.
Any pointer to some code out there dealing with a finite but arbitrary number of heterogenous elements would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:10:20+00:00Added an answer on June 11, 2026 at 7:10 pm

    Generalised Algebraic Data Types, (GADT).

    These let you bring finitely many genuinely heterogenous data types together into one, and are the modern way to do existential types. They sit somewhere in between the data Agent = AH Human | AP Plant | .... approach and the HList approach. You can make all your incredibly heterogenous agents instances of some typeclass, then bundle them together in the AgentGADT. Make sure your typeclass has everything you’ll ever want to do to an Agent in it, because it’s hard to get data back out of a GADT without a function with an explicit type; will you need getHumans [AgentGADT] -> [Human]? or updateHumans :: (Human->Human) -> [AgentGADT] -> [AgentGADT]? That’d be easier with the ordinary abstract data type in my other post.

    Plus points: You can have [AgentGADT] and operate uniformly using class functions, whilst writing weird and wonderfully parameterised data types. Minus points – hard to get your Agent data out once it’s in.

    My favourite introductory text online was GADTs for dummies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting a shared library working in a Java EE environment. In
I'm working with a library that uses Environment.NewLine as it's newline char when writing
I'm working on a library of custom controls and I'm stuck on this error.
I'm working on a library (C++) that will be integrated into clients code. This
I am trying to get a multiple upload library working for my Codeigniter based
I'm trying to get the Boost library working in my C++ projects in Eclipse.
I am trying to get the Aruco AR library working by trying out the
I am working with a library which exposes an interface to work with. One
I am working on a library for procedural texture generation ( https://github.com/mikera/clisk ) which
I'm working using scriptaculous library. However I'm facing some issues with inclusion of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.