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 7996047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:36:08+00:00 2026-06-04T14:36:08+00:00

Thanks to this post I’m getting my head around dependent method types. I have

  • 0

Thanks to this post I’m getting my head around dependent method types. I have a structure similar to the following

trait Environment{
    type Population <: PopulationBase
    protected trait PopulationBase

    def evolveUs(population: Population): Population
}

object FactoredOut{
    def evolvePopulation(env: Environment)(prevPopulation: env.Population): env.Population = {
        env.evolveUs(prevPopulation)
    }
}

I now want to start using actors to spread the work in the FactoredOut part across a cluster. To do this I need a way to pass immutable messages which carry the Environment.

Obviously the following doesn’t work, but demonstrates what I’m trying to do

object Messages{
    case class EvolvePopulation(env: Environment)(prevPopulation: env.Population)
}

What is the correct way to pass the population and it’s enclosing environment around?

(Would have added the dependent-method-types tag, but I don’t have enough points to add a ‘new’ tag)

  • 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-04T14:36:09+00:00Added an answer on June 4, 2026 at 2:36 pm

    Your intuition that you need to pack up both the value of the dependent type (env.Population) and the value that the type depends on (env) as a single object is exactly right.

    Given the definitions you’ve already posted, probably the simplest approach would be something like this,

    // Type representing the packaging up of an environment and a population
    // from that environment
    abstract class EvolvePopulation {
      type E <: Environment
      val env : E
      val prevPopulation : env.Population
    }
    
    object EvolvePopulation {
      def apply(env0 : Environment)(prevPopulation0 : env0.Population) =
        new EvolvePopulation {
          type E = env0.type
          val env : E = env0 // type annotation required to prevent widening from
                             // the singleton type
          val prevPopulation = prevPopulation0
        }
    }
    

    Now if we define a concrete environment type,

    class ConcreteEnvironment extends Environment {
      class Population extends PopulationBase
      def evolveUs(population: Population): Population = population
    }
    

    we can use it directly as before,

    val e1 = new ConcreteEnvironment
    
    val p1 = new e1.Population
    val p2 = e1.evolveUs(p1)
    val p3 = e1.evolveUs(p2)
    

    and we can also package up an environment and population for distribution,

    def distrib(ep : EvolvePopulation) {
      import ep._
      val p4 = env.evolveUs(prevPopulation)
      val p5 = env.evolveUs(p4)
      val p6 = env.evolveUs(p5)
    }
    
    val ep1 = EvolvePopulation(e1)(p3)
    
    distrib(ep1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This post on SO answers most of the questions I have (much thanks to
Thanks to this post I've come up with the following template:- <xsl:variable name=Doc> <xsl:call-template
Thanks to this question (click me!) , I have the Source property of my
I have this regex thanks to another wonderful StackOverflow user /(?:-\d+)*/g I want it
I am using a TStream to read binary data (thanks to this post: How
I've got a diff e-mail sending using Git's post-receive e-mail hook (thanks to this
Thanks to the help I received in this post: How do I use "this"
Following this post which I posted some time ago, I now get the same
I read this post but I don't really understand the code... I have a
Thanks to this post I changed my class to: class Foo(db.Model): name = db.StringProperty(multiline=True)

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.