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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:46:53+00:00 2026-06-13T04:46:53+00:00

I was trying to play around a bit with higher-kinds and type bounds when

  • 0

I was trying to play around a bit with higher-kinds and type bounds when I bumped into this problem. My use case is that I want to be able to parameterize GenericAction instances with any subtype of Request, or the Request type itself. The Action trait extends the GenericAction trait with a default type of Request (in this case only anonymous instances of Request will be spawned).

trait Request[+A]

trait GenericAction[A, R[_] <: Request[_]]

trait Action[A] extends GenericAction[A, Request]

trait ActionBuilderBase[R[_] <: Request[_], G[_] <: GenericAction[_,R]]

ActionBuilderBase has utility methods that are shared with the sub-traits ActionBuilder and ActionBuilder2. ActionBuilder generates default Action[A] and Request[A] instances.

trait ActionBuilder extends ActionBuilderBase[Request,Action]

So far so good, but when I try to create another trait that extends ActionBuilderBase with a subtype of R and GenericAction (in this case anonymous instances of GenericAction would be created), it fails to compile. I guess the reason is that in the case of the first ActionBuilder, the request type has already been “filled in” (since Action[A] already has a request type == Request) , unlike the example below. What would I need to “fill in” in order for this example to work?

//Fails with "GenericAction takes two type parameters, expected: one" - what should the type annotation for GenericAction look like?
trait ActionBuilder2[R[_] <: Request[_]] extends ActionBuilderBase[R,GenericAction]
  • 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-13T04:46:54+00:00Added an answer on June 13, 2026 at 4:46 am

    It would be nice in this situation to be able to write something like this:

    trait ActionBuilder2[R[_] <: Request[_]] extends
      ActionBuilderBase[R, GenericAction[_, R]]
    

    To indicate that you want to partially apply GenericAction. Unfortunately that’s not valid Scala syntax (although Erik Osheim has a compiler plugin that lets you write something very similar).

    You can use the “type lambda trick”, however:

    trait ActionBuilder2[R[_] <: Request[_]] extends
      ActionBuilderBase[R, ({ type L[A] = GenericAction[A, R] })#L]
    

    See this answer for a detailed explanation of how it works.

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

Sidebar

Related Questions

I'm currently trying to play around with OpenCV but I ran into a bit
I'm trying to compile this example and play around with it a bit. I've
I'm having a bit of a play around with IIS7, just trying to catch
I'm trying to play around with some music clustering algorithms, and I thought that
I'm trying to follow this guide to play around with Google Predict from the
I am trying to play around with erlubi, a bit of software written to
I have been trying to play around with this for a long time and
Ran into an odd bug while trying to play around with some perlin noise
I'm trying to play around with turning an image into mosaic bricks like the
Hey, I'm trying to play around a with sysfs a little bit, to get

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.