scala - Is it possible to "mix in: additional type constraints -
i'd add constraints type field in trait additional traits mixed in can't seem find way express it. appreciated:
trait events { def be() = println("b") } trait create { self : events => def create() = println("c") } trait update { self : events => def update() = println("u") } trait delete { self : events => def delete() = println("d") } trait eventhandler { type myevents <: events val myevents : myevents } trait creation { self: eventhandler => override type myevents <: create } def h(events: eventhandler creation) : unit = { events.myevents.be() // <== wont' compile events.myevents.create() } compiler says:
<console>:12: error: value not member of events.myevents
ok of previous comments in error, didn't realize self typing hides interface you're working , not same "extends". here's link explains better:
http://www.andrewrollins.com/2014/08/07/scala-cake-pattern-self-type-annotations-vs-inheritance/
there's many logical conflicts creates in code, , won't attempt rework here. conflicts in code come down - of logic opening trait api, , of self-types hiding them. here's example helped me understand why
trait { def x:int } trait b { self:a => } def workwithb(b:b): unit ={ b.x //wont' compile, forced hidden. }
Comments
Post a Comment