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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:17:41+00:00 2026-05-15T12:17:41+00:00

I was messing around with Scala 2.8 for fun and trying to define a

  • 0

I was messing around with Scala 2.8 for fun and trying to define a pimp which adds an “as” method to type constructors, allowing to convert from one functor to another (please overlook the fact that I’m not necessarily dealing with functors here). So for instance, you could use it like this:

val array:Array[T]
val list:List[T] = array.as[List]

So here’s what I tried to do:

object Test {
    abstract class NatTrans[F[_], G[_]] {
        def convert[T](f:F[T]):G[T]
    }

    implicit def array2List:NatTrans[Array, List] = new NatTrans[Array, List] { 
        def convert[T](a:Array[T]) = a.toList
    }

    // this next part gets flagged with an error
    implicit def naturalTransformations[T, F[_]](f:F[T]) = new {
        def as[G[_]](implicit n:NatTrans[F, G]) = n convert f
    }
}

however the definition of naturalTransformations is flagged with the error “can’t existentially abstract over parameterized type G[T]”. To fix this, I can rewrite naturalTransformations along with an additional class Transformable like so:

class Transformable[T, F[_]](f:F[T]) {
    def as[G[_]](implicit n:NatTrans[F, G]) = n convert f
}

implicit def naturalTransformations[T, F[_]](f:F[T]) = new Transformable[T, F](f)

and it appears to work. But it seems like my first attempt should’ve been equivalent, so I’m curious why it failed and what the error message means.

  • 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-15T12:17:42+00:00Added an answer on May 15, 2026 at 12:17 pm

    My hunch would be that this is because due to the following statements in the spec, § 6.11 , blocks:

    A locally defined type definition type t = T is bound by the existential clause
    type t >: T <: T . It is an error if t carries type parameters.

    And a structural instance creation expression is evaluated to a block, so

    
    new {def greet{println("hello")}}
    

    is a shorthand for

    
    { class anon$X extends AnyRef{ def greet = println("hello") }; new anon$X }
    

    so it evaluates to a block expression (according to § 6.10 of the spec), with the aforementioned restriction. Why this restriction is there I do not know, however. The error that is thrown can be found in the Typers class at this location, which seems to confirm that this restriction is the cause of the error that you see.
    As you mentioned, encoding the function in a class removes the block expression restriction:

    
    scala> class N[M[_]]
    defined class N
    
    scala> class Q { def as[M[_]](n:N[M]) = null}
    defined class Q
    
    scala> new { def as[M[_]](n:N[M]) = null}       
    :7: error: can't existentially abstract over parameterized type M
           new { def as[M[_]](n:N[M]) = null}
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been messing around with a search engine and i am trying to
Just messing around with Rails 3.1, which separates stylesheets via controllers. I'm assuming there
just messing around, trying to expand my bag o' tricks: I was just experimenting
I started messing around with generics in Scala, and it is a tough cookie
Messing around with some CSS trying to learn some stuff as I haven't done
I was just messing around with XNA and trying to get a simple player
So I was messing around with some easy problems to get better at scala
So I'm just messing around learning to create a Space invaders type game. I
Been messing around with Hibernate and PostgreSQL trying to get it to work as
I have been messing around with my meta descriptions, trying to make them more

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.