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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:37:09+00:00 2026-06-05T08:37:09+00:00

he following compiles: import scala.collection.mutable.MutableList abstract class GeomBase[T <: DTypes] { val grids =

  • 0

he following compiles:

import scala.collection.mutable.MutableList

abstract class GeomBase[T <: DTypes]
{  
  val grids = new MutableList[GridBase]

  def hexs: MutableList[GridBase#HexG with T#HexTr] = grids.flatMap(_.hexs.toList)
  //the above compiles fine

  abstract class GridBase
  { 
    val hexs: MutableList[HexG with T#HexTr] = new MutableList[HexG with T#HexTr]


    class HexG(coodI: Cood) extends Hex
    {
    }
  }
}

But when I change the line from this

def hexs: MutableList[GridBase#HexG with T#HexTr] = grids.flatMap (_.hexs.toList)

to this (changing the MutableList into a List)

def hexs: List[GridBase#HexG with T#HexTr] = grids.flatMap (_.hexs.toList)

it doesn’t compile any more. This doesn’t compile either

def hexs: MutableList[GridBase#HexG with T#HexTr] = grids(0).hexs

It wont compile, saying I need a MutableList in the former case and type incompatibility in the latter. I don’t understand why. Just to clarify in case its causing confusion HexG is an inner class of GridBase which is itself an inner class of GeomBase.

Update: Travis Brown’s answer seems to provide the correct explanation for the first error. I’ve changed all the uses of MutableList to List. Surprisingly this not only stopped the first error but also the second. I also got errors when trying to use the types outside of the outermost GeomBase class. I got a compiler crash. when instantiating the type. Changing to Lists from MutableLists again unexpectedly removed one of these errors but not the compiler crash. I had been using Scala Eclipse plugin 2.1 special edition for 2.10.0-M3. This leads me to the conclusion that there still may be problems with the Scala compiler and path dependant types.

  • 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-05T08:37:11+00:00Added an answer on June 5, 2026 at 8:37 am

    The problem here (probably) doesn’t have anything to do with the path-dependent types. Consider the following:

    val xs: MutableList[Seq[Int]] = new MutableList ++ Seq(1 to 2, 3 to 4)
    

    Now we can do the following, for example:

    scala> xs.flatMap(_.toList)
    res0: scala.collection.mutable.MutableList[Int] = MutableList(1, 2, 3, 4)
    

    But a MutableList isn’t a List:

    scala> xs.flatMap(_.toList): List[Int]
    <console>:10: error: type mismatch;
     found   : scala.collection.mutable.MutableList[Int]
     required: List[Int]
                  xs.flatMap(_.toList): List[Int]
    

    If we’d called it a Seq[Int], for example, we’d be fine, since Seq is a supertype of MutableList. List isn’t (despite the name).

    In your last example you’re getting an error because grids(0).hexs doesn’t have the right type—it’s not a MutableList[GridBase#HexG with T#HexTr]. I’m not sure what it is, since you haven’t shared that code with us.


    As a footnote: interestingly (or maybe not), the following does work:

    xs.flatMap(_.toList)(collection.breakOut): List[Int]
    

    Don’t do this, though. breakOut is weird magic.

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

Sidebar

Related Questions

My code snippets are below import scala.collection.mutable.HashMap val crossingMap = new HashMap[String, Option[Long]] val
My code is as follows import scala.collection.mutable.HashMap type CrossingInterval = (Date, Date) val crossingMap
The following compiles fine: Object o = new Object(); System.out.println(o instanceof Cloneable); But this
This confuses me. The following compiles fine under Eclipse. package com.example.gotchas; public class GenericHelper1
Why does the following module not compile on Scala 2.8.RC[1,2]? object Test { import
The following code raises an ambiguous reference to value at compile time: import flash.display.Sprite;
I'm trying to compile the following code with GHC: module Test where import Maybe
I've come across some C code that I don't quite understand. The following compiles
The following code compiles fine in one C++ project in RenderingEngine.cpp : IRenderingEngine* CreateRenderer1()
The following program compiles with ifort (version 12) but not with GFortran (up to

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.