Breaking up the source of path-dependent types

50 views
Skip to first unread message

Alan Burlison

unread,
Nov 17, 2015, 10:57:20 AM11/17/15
to scala-user
I'm using path-dependent types and they work really well for the domain
I'm modelling. However there's one issue - I have quite a few
class-dependent types and as far as I can tell they all have to be
textually nested within the outer class. This makes for a rather large,
monolithic source file that ideally I'd like to split up into separate
files for each path-dependent type, but as far as I can tell there's no
way of doing that. Is that correct?

--
Alan Burlison
--

Stephen Compall

unread,
Nov 23, 2015, 7:48:37 AM11/23/15
to Alan Burlison, scala-user
Tradition is to mix traits from separate sources. However, this is monolithic in another sense. There's another approach, given that x.T is just x.type#T.

class Foo {
class Bar
def dowith(b: Bar) = 42
}

case class HasBars[FX <: Foo](bar: FX#Bar)

val x = new Foo
val hb = HasBars(new x.Bar)
// hb has type HasBars[x.type]
// meaning this compiles
x.dowith(hb.bar)

[FX <: Foo] is also a sensible method type parameter. I've used this technique to split up reflection universe stuff (e.g. add methods) where using dependent method types was inconvenient (surprisingly common).

--
Stephen Compall
If anyone in the MSA is online, you should watch this flythrough.
Reply all
Reply to author
Forward
0 new messages