Re: Re: Scala - a Roadmap

martin odersky <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <CAENVNkYo4e1TZgpp_j1QChcofcG7W86kgSupZSG265pfwUZBWw@mail.gmail.com>
On Mon, Jun 15, 2015 at 5:08 AM, Shelby <[email protected]> wrote:
> How would the unification of higher-kinded and abstract types express the
> following semantics?
>
> trait Functor[T, Subtype[T] <: Functor[T, Subtype[T]] {
>   def map : (T => R) => Subtype[R]
> }
>
> Am I correct to assume the following?
>
> trait Functor {
>   type T
>   type Subtype <: Functor
>   def map : (T => R) => Subtype
> }
>
That would lose information. I believe you have to write it like this:

trait Functor { functor =>
  type T
  type Subtype <: Functor { type T = functor.T }
  def map[R] : (T => R) => Subtype { type T = R }
}

To avoid misunderstanding (because I found many people do
misunderstand this point): That would be a compiler expansion; you
will usually still write the original parameterized version:

> trait Functor[T, Subtype[T] <: Functor[T, Subtype[T]] {
>   def map : (T => R) => Subtype[R]
> }
>

Cheers

 - Martin

> --
> You received this message because you are subscribed to the Google Groups
> "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.



-- 
Martin Odersky
EPFL

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.