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

  • SEARCH
  • Home
  • 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 8007211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:45:13+00:00 2026-06-04T17:45:13+00:00

When calling methods with type parameters in Scala, I often try to arrange the

  • 0

When calling methods with type parameters in Scala, I often try to arrange the code so that the type inferencer can find out itself about the type parameters and not need me to fill them out. In some circumstances, it fails and I have to provide them manually.

Most of the time, this is not a problem, but for methods with several type parameters (e.g., most methods requiring an implicit CanBuildFrom), I was wondering whether there was a way to help the type inferencer by giving it only one of the needed type parameters, and asking it to try and guess the other ones. It looks like internally, it must be doing such things anyway, since it sometimes produces error messages of the form “expected type A[B, ?] but got A[C, D]”, which would means that of the two type parameters of A, the it could find out the first one B but has no info about the second one.

Use case: Tomasz’s question, where this code:

def firstAndLast[CC, A, That](seq: CC)(implicit asSeq: CC => Seq[A], cbf: CanBuildFrom[CC, A, That]): That = {
  val b = cbf(seq)
  b += seq.head
  b += seq.last
  b.result
}

cannot be called with List("abc", "def") map firstAndLast, but this would work:

List("abc", "def") map firstAndLast[String, Char, String]

In this example, my question boils down to: is there any way to tell the type inferencer that the CC parameter should be String, and ask it to find out itself about A and That? Something like, in essence,

List("abc", "def") map firstAndLast[CC = String]

or

List("abc", "def") map firstAndLast[String, <guess>, <guess>]

I know these lines don’t work; I’m looking for a workaround (or for pointers to future language features that have been discussed and which could lead to this).

  • 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-04T17:45:15+00:00Added an answer on June 4, 2026 at 5:45 pm

    No, you can’t. There’s type lambdas and type itself which would serve for types (as in classes and traits), but not for type parameters. For example:

    // Declaring a type alias
    type StringMap[Elem] = Map[String, Elem]
    
    // Calling an `def f[M[_]]` but passing a `Map`
    f[({type l[A]=Map[String,A]})#l]
    
    // note that f could also be called like this:
    f[StringMap]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with the MyClass::function(); style of calling methods and can't figure out
I recognized that calling a method on an Oracle Object Type takes longer when
I try to implement an initialization method for my own type. However after calling
I have some code that I want to refactor. I have lots of methods
I have a couple of standard ASP.NET web methods that I'm calling from javascript
When calling methods with a signature that has a delegate, using lamba syntax, Visual
I'm having trouble getting PEX to automatically cover methods calling Linq extension methods, such
The extension methods: Response.AsJson Response.AsXml works fine when calling it from the constractor like:
I'm dealing with viewDidUnload and dealloc methods and I've founded a problem when calling
I have the following code (calling a method returning IEnumerable): FibonacciWithLinq.Skip(delegate() { return 5;

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.