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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:34:14+00:00 2026-06-07T16:34:14+00:00

The general goal: Suppose for instance I want to develop a very pluggable issue

  • 0

The general goal:

Suppose for instance I want to develop a very pluggable issue tracker. Its core implementation might only support a ticket id and a description. Other extensions might add support for various other fields, yet those fields might exist in the database on the same table. Even if not, the number of queries to the database should not need to increase along with the number of extensions. They should be able to contribute to the definition of the query.

Item[A, B, R[_]] would represent a column, with A for the table type (has the column representations), B as the data type, and R as the type constructor representing a column of type B. So R[B] might be ScalaQuery’s NamedColumn[String], for example.

Right now I’m trying to make a typeclass to handle building the “query”.

The problem:

The line starting with val q (at the end) should read simply val q = query(items) and still compile. Various attempts yield either an error that inferred type arguments don’t conform to expected type arguments, due to defaultNext inferring B0 and/or B to Nothing, or a “diverging implicit expansion” error, or other errors. I think the implicit error is triggered by incorrect type inference though.

I’ve already wasted quite a few days on this (it’s for an open-source project of mine) so if someone could kindly help out I would really really appreciate it.

  class CanBuildQuery[A, B, R[_], Q, I <: Item[A, B, R]](val apply: I => A => Q)

  trait Low {
    implicit def defaultNext[A, B, R[_], B0, P <: Item[A, B0, R], I <: NextItem[A, B, B0, R, P], PQ](
      implicit cbq: CanBuildQuery[A, B0, R, PQ, P]
    ): CanBuildQuery[A, B, R, (PQ, R[B]), I] =
      new CanBuildQuery[A, B, R, (PQ, R[B]), I](sys.error("todo"))
  }

  object CanBuildQuery extends Low {
    implicit def defaultFirst[A, B, R[_]]:
      CanBuildQuery[A, B, R, R[B], FirstItem[A, B, R]] =
        new CanBuildQuery[A, B, R, R[B], FirstItem[A, B, R]](_.get)
  }

  def query[A, B, R[_], Q, I <: Item[A, B, R]](
    i: I with Item[A, B, R]
  )(
    implicit cbq: CanBuildQuery[A, B, R, Q, I]
  ): A => Q =
    cbq apply i

  trait Item[A, B, +R[_]] {    
    def get: A => R[B]
  }    
  trait FirstItem[A, B, +R[_]] extends Item[A, B, R] {    
    def get: A => R[B]
  }    
  trait NextItem[A, B, B0, +R[_], I <: Item[A, B0, R]] extends Item[A, B, R] {   
    val prev: I
    def get: A => R[B]
  }

  val items =
    new NextItem[Boolean, String, Long, Option, FirstItem[Boolean, Long, Option]]{
      val get = { _:Boolean => "hello" }
      val prev = new FirstItem[Boolean, Long, Option] {
        val get = { _:Boolean => 73 }
      }
    }

  val q = query(items)(CanBuildQuery.defaultNext(CanBuildQuery.defaultFirst))
  • 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-07T16:34:17+00:00Added an answer on June 7, 2026 at 4:34 pm

    With G-d’s help, including some insights and suggestions from Josh Seureth, I got it to work:

      trait Item[A] {
        type B
        type R[_]
        def get: A => R[B]
      }
      object Item {
        def apply[A, B, R[_]](get: A => R[B])(render: B => String => String) = {
          val get0 = get
          type B0 = B
          type R0[T] = R[T]
          new FirstItem[A] {
            type B = B0
            type R[T] = R0[T]
            def get = get0
          }
        }
      }
      trait FirstItem[A] extends Item[A] {
        type B
        def get: A => R[B]
        def &(item: Item[A]) =
          new NextItem[A] {
            type P = FirstItem.this.type
            type B = item.B
            type R[T] = item.R[T]
            val prev = FirstItem.this: FirstItem.this.type
            def get = item.get
          }
      }
      trait NextItem[A] extends Item[A] {
        type B
        type P <: Item[A]
        type _P = P
        val prev: P
        def get: A => R[B]
        def &(item: Item[A]) =
          new NextItem[A] {
            type P = NextItem.this.type
            type B = item.B
            type R[T] = item.R[T]
            val prev = NextItem.this: NextItem.this.type
            def get = item.get
          }
      }
    
      class CanBuildQuery[A, +Q, -I](val apply: I => A => Q)
      class CanBuildQueryImplicits {
        def apply[A, ]
        implicit def defaultNext[A, I <: NextItem[A], PQ](implicit cbq: CanBuildQuery[A, PQ, I#P]): CanBuildQuery[A, (PQ, I#R[I#B]), I] =
          new CanBuildQuery[A, (PQ, I#R[I#B]), I](ni => a => query(ni.prev)(cbq)(a) -> ni.get(a).asInstanceOf[I#R[I#B]])
        implicit def defaultFirst[A, B, I <: FirstItem[A]]: CanBuildQuery[A, I#R[I#B], I] =
          new CanBuildQuery[A, I#R[I#B], I](i => i.get.asInstanceOf[A => I#R[I#B]])
      }
      def query[A, Q, I <: Item[A]](i: I with Item[A])(implicit cbq: CanBuildQuery[A, Q, I]): A => Q = cbq apply i
    }
    
      val items =
        Item((_: Field.type).id)(x => _ + " " + x) &
          Item((_: Field.type).name)(x => _ + " " + x) &
          Item((_: Field.type).allowMultiple)(x => _ + " " + x)
    
       val q = query(items) apply Field
       println(q)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

General context : MVVM application. I have a View called JobView. Its DataContext is
In general, I try very much to respect a modules privacy (If a variable
I'm trying to achieve the following goal: Using this general singleton class: abstract class
This is the general goal I am trying to achieve: My VB.NET program will
I am hoping to receive some general guidance on accomplishing a seemingly simple goal.
The text in italics describes my general goal, if anyone is interested. Question is
General wisdom is when you remove a component from the stage you also need
General javascript question here, which would also be good to know how(if possible) to
general question is i like to build logger class that writes to single log
General approach in GWT is to use Panels and then apply custom CSS themes

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.