This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Is there a type bound that makes this work?

2 replies
Meredith Gregory
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Dear Scalarazzi,

trait ToDo[ToBe <: ???] { object Body extends ToBe }

Best wishes,

--greg

--
L.G. Meredith
Managing Partner
Biosimilarity LLC
1219 NW 83rd St
Seattle, WA 98117

+1 206.650.3740

http://biosimilarity.blogspot.com
milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: Is there a type bound that makes this work?

2009/10/8 Meredith Gregory :
> trait ToDo[ToBe <: ???] { object Body extends ToBe }

You can't extend a type parameter or abstract type member directly,
but you can get an equivalent effect using abstract members and
refinements,

trait ToBe
trait ToDo { val Body : ToBe }

trait MyToBe extends ToBe

new ToDo { object Body extends MyToBe } // encoding of new ToDo[MyToBe]

Cheers,

Miles

Luc Duponcheel
Joined: 2008-12-19,
User offline. Last seen 34 weeks 3 days ago.
Re: Is there a type bound that makes this work?
this works with AnyRef as type bound

trait ToDoModule { type ToBe ; trait ToDo[ToBe <: AnyRef] }

class Foo

object ToDoModuleWithFoo
extends ToDoModule { type ToBe = Foo ; object ToDo extends Foo }


it is, more involved than Miles suggestion

2009/10/8 Miles Sabin <miles [at] milessabin [dot] com>
2009/10/8 Meredith Gregory <lgreg [dot] meredith [at] gmail [dot] com>:
> trait ToDo[ToBe <: ???] { object Body extends ToBe }

You can't extend a type parameter or abstract type member directly,
but you can get an equivalent effect using abstract members and
refinements,

trait ToBe
trait ToDo { val Body : ToBe }

trait MyToBe extends ToBe

new ToDo { object Body extends MyToBe } // encoding of new ToDo[MyToBe]

Cheers,


Miles

--
Miles Sabin
tel: +44 (0)7813 944 528
skype:  milessabin
http://www.chuusai.com/
http://twitter.com/milessabin



--
  __~O
 -\ <,
(*)/ (*)

reality goes far beyond imagination

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland