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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:00:57+00:00 2026-06-08T22:00:57+00:00

In the following scenario, by-name parameters cause conflict with functions. Given some serialization infrastructure:

  • 0

In the following scenario, by-name parameters cause conflict with functions.

Given some serialization infrastructure:

trait Tx {
   def readSource[A](implicit ser: Serializer[A]) : Source[A] = 
      new Source[A] { 
         def get(implicit tx: Tx): A = ser.read(new In {})
      }
}    
trait In
trait Source[A] { def get(implicit tx: Tx): A }
trait Serializer[A] { def read(in: In)(implicit tx: Tx): A }

And an example type along with its serializer:

// needs recursive access to itself. for reasons
// beyond the scope of this questions, `self` must
// be a by-name parameter
class Transport(self: => Source[Transport])

// again: self is required to be by-name
def transportSer(self: => Source[Transport]) : Serializer[Transport] = 
   new Serializer[Transport] { 
      def read(in: In)(implicit tx: Tx): Transport = new Transport(self)
   }

Now imagine a wrapper called Hook which deals with the recursive/mutual connectivity:

trait Hook[A] {
   def source: Source[A]
}

And its serializer:

def hookSer[A](peerSelf: Source[A] => Serializer[A]) : Serializer[Hook[A]] = 
   new Serializer[Hook[A]] {
      def read(in: In)(implicit tx: Tx) : Hook[A] =
         new Hook[A] with Serializer[A] {
            val source: Source[A] = tx.readSource[A](this)
            def read(in: In)(implicit tx: Tx) : A = peerSelf(source).read(in)
         }
   }

Then the following fails:

val hs = hookSer[Transport](transportSer)

<console>:15: error: type mismatch;
 found   : => Source[Transport] => Serializer[Transport]
 required: Source[Transport] => Serializer[Transport]
          val hs = hookSer[Transport](transportSer)
                                      ^

How can this be fixed without changing by-name parameters to functions (as far as possible)?

  • 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-08T22:00:58+00:00Added an answer on June 8, 2026 at 10:00 pm

    It seems one can write the type (=> Source[A]) => Serializer[A]:

    def hookSer[A](peerSelf: (=> Source[A]) => Serializer[A]) : Serializer[Hook[A]] = ...
    
    val hs = hookSer[Transport](transportSer)
    val h  = hs.read(new In {})(new Tx {})
    val t  = h.source.get(new Tx {})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider e.g. the following scenario: we give some entry point URL (something like https://our.server/customer-name/entry-point.js
Following scenario: I have user object: ... @Column(name = TITLE) private String title; @NotNull
The following scenario is given: /Collection1 (a number of users are subscribed to this
Original Question Consider the following scenario: public abstract class Foo { public string Name
How to do following scenario: I have some DataTable which contains for example some
I have the following scenario, I have a table column with the name categoryid
Imagine the following scenario: some xml file is downloaded from server and stored on
I have the following scenario: Due to an unfortunate legacy database, I have some
I am trying to find records that has the following scenario. ID | name
I have the following scenario: I have five fields in my database (name, email,

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.