illegal dependent method type?

307 views
Skip to first unread message

William Uther

unread,
Feb 18, 2011, 1:28:05 AM2/18/11
to scala...@googlegroups.com
Hi all,

Compiling code like this:

class Outer1 {
class Inner()

def makeInner(): Inner = new Inner()
}

class Outer2 {
def myFunc(o: Outer1) = o.makeInner()
}

I get an error like this:

scala> class Outer2 {
| def myFunc(o: Outer1) = o.makeInner()
| }
<console>:7: error: illegal dependent method type
def myFunc(o: Outer1) = o.makeInner()
^
Google reveals that this is known and that the compile option "-Ydependent-method-types" will make it go away. But it appears to have been "experimental" for a number of years, and that suggests that it is not about to become a supported feature any time soon.

Should I be working about this problem, or using -Ydependent-method-types?

Cheers,

Will :-}

P.S. While looking through "scala -Y" I found "-Yno-completion". Is there any easy way to make that a default option? e.g. is there a .scalarc I could add it to? A SCALA_OPTS environment variable?

Adriaan Moors

unread,
Feb 18, 2011, 5:01:35 AM2/18/11
to scala...@googlegroups.com
Hi William,

On Fri, Feb 18, 2011 at 7:28 AM, William Uther <willu.mai...@cse.unsw.edu.au> wrote:
Hi all,

Compiling code like this:

class Outer1 {
 class Inner()

 def makeInner(): Inner = new Inner()
}

class Outer2 {
 def myFunc(o: Outer1) = o.makeInner()
}

I get an error like this:

scala> class Outer2 {
    |   def myFunc(o: Outer1) = o.makeInner()
    | }
<console>:7: error: illegal dependent method type
        def myFunc(o: Outer1) = o.makeInner()
                   ^
that's because the inferred type of myFunc is o.Inner, where o refers to myFunc's argument
thus, the method's type depends on (the value of) one of its arguments

you can make these types legal with the switch you mention below -- it should work just fine (I hope it will be on by default in the major release after 2.9)

the alternative is to aproximate the method's result type with a type that does not depend on an argument 
 
cheers
adriaan

Dennis Haupt

unread,
Feb 18, 2011, 5:14:29 AM2/18/11
to adriaa...@epfl.ch, scala...@googlegroups.com
i tried something like this for a type driven compile time safe tic tac toe
logic. it worked to some degree, but not completely.

-------- Original-Nachricht --------
> Datum: Fri, 18 Feb 2011 11:01:35 +0100
> Von: Adriaan Moors <adriaa...@epfl.ch>
> An: scala...@googlegroups.com
> Betreff: Re: [scala-user] illegal dependent method type?

Adriaan Moors

unread,
Feb 18, 2011, 6:15:52 AM2/18/11
to Dennis Haupt, scala...@googlegroups.com
Hi Dennis,

I'd love to hear the limitations you ran into! Please have a look at our oopsla paper, "Type Classes as Objects and Implicits" for some examples of combining dependent method types and implicits.

cheers
adriaan

Dennis Haupt

unread,
Feb 18, 2011, 6:22:02 AM2/18/11
to adriaa...@epfl.ch, scala...@googlegroups.com
i'll prepare en example within the next 34 hours.

-------- Original-Nachricht --------
> Datum: Fri, 18 Feb 2011 12:15:52 +0100
> Von: Adriaan Moors <adriaa...@epfl.ch>
> An: Dennis Haupt <h-s...@gmx.de>
> CC: scala...@googlegroups.com


> Betreff: Re: [scala-user] illegal dependent method type?

> Hi Dennis,


>
> I'd love to hear the limitations you ran into! Please have a look at our
> oopsla paper, "Type Classes as

> <http://ropas.snu.ac.kr/~bruno/papers/TypeClasses.pdf>
> *Objects <http://ropas.snu.ac.kr/~bruno/papers/TypeClasses.pdf>* and
> <http://ropas.snu.ac.kr/~bruno/papers/TypeClasses.pdf>
> *Implicits <http://ropas.snu.ac.kr/~bruno/papers/TypeClasses.pdf>" for
> some
> examples of combining dependent method types and implicits.*
>
> **cheers

HamsterofDeath

unread,
Feb 19, 2011, 8:41:17 AM2/19/11
to scala...@googlegroups.com
here you go. you need to adjust the package names. the main method shows
the error and is commented. i tried to compile with -Xexperimental

didn't look at the papers yet. who came up with that name?

TypeSafeTicTacToe.scala
ChurchNumerals.scala
Reply all
Reply to author
Forward
0 new messages