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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:48:26+00:00 2026-05-24T13:48:26+00:00

In order to create a DSL for my new Scala project I’ve written the

  • 0

In order to create a DSL for my new Scala project I’ve written the following code:

trait DocDB[O] {
    def searchFor[I] (docs: Iterable[I], queryStrategy: QueryStrategy[I, DocDB[_]]): Iterable[(I,O)]
}
trait QueryStrategy[I, +F <: DocDB[_]]

class In  // class of input documents
class Out // class of output documents
// MyDocDB
object MyDocDB extends DocDB[Out] {
    def searchFor[I] (docs: Iterable[I], queryStrategy: QueryStrategy[I, DocDB[_]]) = List()
}
// MyQueryStrategy for In and MyDocDB
implicit object MyQueryStrategy extends QueryStrategy[In, MyDocDB.type]

implicit def listExt[I] (items: Iterable[I]) = new {
    def findAt[O, F <: DocDB[O]](docDB: F) = new {
        def apply(implicit queryStrategy: QueryStrategy[I, F]): Iterable[(I,O)] = {
            docDB.searchFor[I](items, queryStrategy)
        }
    }
}

What I actually want is to be able to write

val out1: Iterable[(In, Out)] = List[In]() findAt MyDocDB

to find corresponding documents for my input documents at MyDocDB by using the query strategy MyQueryStrategy (defined as default for this input type and DocDB via implicit).

Unfortunately, the Scala compile has a problem with that line. It claims that it can not infer the types:

error: inferred type arguments [Nothing,test.StackOverflow.MyDocDB.type] do not conform to method findAt's type parameter bounds [O,F <: test.StackOverflow.DocDB[O]]
val out1: Iterable[(In, Out)] = List[In]() findAt MyDocDB

Somehow it infers Nothing instead of Out. How can I solve this without telling the compiler explicitly that it should assume O to be of type Out? I mean, the following works but does not lead to a concise DSL:

val out2: Iterable[(In, Out)] = List[In]().findAt[Out, MyDocDB.type](MyDocDB).apply(MyQueryStrategy)

Any suggestions?

Edit:

Thanks very much for your answers. I finally took paradigmatic’s solution, since it allows that query strategies can be targeted to specific DocDBs which I actually need in my project. In addition to paradigmatic’s solution I replaced the listExt function by

implicit def listExt[I] (items: Iterable[I]) = new {
    def findAt[F <: DocDB](docDB: F)(implicit queryStrategy: QueryStrategy[I, F]): Iterable[(I,F#O)] = {
        docDB.searchFor[I](items, queryStrategy)
    }
}

so that I can omit the apply method and implicit QueryStrategy:

val out1: Iterable [(In,Out)] = List[In]() findAt MyDocDB

Thanks again.

  • 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-05-24T13:48:29+00:00Added an answer on May 24, 2026 at 1:48 pm

    I have some success by turning O in an abstract type in DocDB and using type projection:

    trait DocDB {
      type O
      def searchFor[I](
        docs: Iterable[I],
        queryStrategy: QueryStrategy[I, DocDB]
      ): Iterable[(I,O)]
    }
    
    trait QueryStrategy[I, +F <: DocDB]
    
    class In  // class of input documents
    class Out // class of output documents
    
    object MyDocDB extends DocDB {
    
      type O = Out
      def searchFor[I](
        docs: Iterable[I], 
        queryStrategy: QueryStrategy[I, DocDB]
      ) = List()
    }
    
    implicit object MyQueryStrategy extends QueryStrategy[In, MyDocDB.type]
    
    implicit def listExt[I] (items: Iterable[I]) = new {
      def findAt[F <: DocDB](docDB: F) = new {
        def apply(implicit queryStrategy: QueryStrategy[I, F]): 
        Iterable[(I,F#O)] = {
          docDB.searchFor[I](items, queryStrategy)
        }
      }
    }
    

    It seems to work:

    scala> val out1: Iterable [(In,Out)] = List[In]() findAt MyDocDB apply
    out1: Iterable[(In, Out)] = List()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing the following code in order to create a PDF file with
I am using the following code in order to create a UIScrollView : UIScrollView
I'm using the following script in my website in order to create pagination next-previous
I tried following the instructions here in order to create a static website on
i have used the following headers in order to create xls files that contains
I'm using the following function in order to create an UUID and write it
I'm using Adaptive Payments API in order to create a new parallel payment. I'm
I have this code here in order to create a tag cloud, the tags
I've been following this guide in order to create tabs on my web application.
I'm trying to do the following(in this order): Create a Rich Text Format file

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.