This does not hide the type of MSequitor, but: trait MBrace[C[X] <: MBrace[C,X],A] { def nest( a : A ) : C[A] def flatten[T <: C[C[A]]]( bsq : T ) : C[A] }
// a monad that is a Seq trait MBraceSeq[C[X] <: MBrace[C,X] with Seq[X],A] extends MBrace[C,A] trait MSequitor[A] extends Seq[A] with MBrace[MSequitor,A] object MBraceSequitor { // one of the simplest witnesses of monad i can find private case class MSequitorImpl[A]( a_ : A* ) extends MSequitor[A] { override def nest( a : A ) = new MSequitorImpl[A]( a ) override def flatten[T <: MSequitor[MSequitor[A]]]( bsq : T ) : MSequitor[A] = { (new MSequitorImpl[A]( ) /: bsq)( { ( acc : MSequitor[A], e : MSequitor[A] ) => new MSequitorImpl[A]( acc ++ e : _* ) } ) } override def length = a_.length override def elements = a_.elements override def apply( n : Int ) = a_.apply( n ) } } // a statement of the instance relation class MBraceSequitor[A] extends MBraceSeq[MSequitor,A] { import MBraceSequitor._ val empty : MSequitor[A] = new MSequitorImpl[A]( ) override def nest( a : A ) = empty.nest( a ) override def flatten[T <: MSequitor[MSequitor[A]]]( bsq : T ) : MSequitor[A] = empty.flatten( bsq ) } Kris On Fri, Jun 26, 2009 at 12:47 PM, Meredith Gregory<lgreg.mered...@gmail.com> wrote: > All, > > Am i being stupid or is it impossible in the code below to construct a > natural way to hide the concrete case class? > > Best wishes, > > --greg > > trait MBrace[C[X] <: MBrace[C,X],A] { > def nest( a : A ) : C[A] > def flatten[T <: C[C[A]]]( bsq : T ) : C[A] > } > > // a monad that is a Seq > trait MBraceSeq[C[X] <: MBrace[C,X] with Seq[X],A] extends MBrace[C,A] > > // one of the simplest witnesses of monad i can find > case class MSequitor[A]( a_ : A* ) extends Seq[A] with MBrace[MSequitor,A] { > override def nest( a : A ) = new MSequitor[A]( a ) > override def flatten[T <: MSequitor[MSequitor[A]]]( bsq : T ) : > MSequitor[A] = { > (new MSequitor[A]( ) /: bsq)( { > ( acc : MSequitor[A], e : MSequitor[A] ) => ( acc ++ e > ).asInstanceOf[MSequitor[A]] > } ) > } > override def length = a_.length > override def elements = a_.elements > override def apply( n : Int ) = a_.apply( n ) > } > > // a statement of the instance relation > class MBraceSequitor[A] extends MBraceSeq[MSequitor,A] { > val empty : MSequitor[A] = new MSequitor[A]( ) > override def nest( a : A ) = empty.nest( a ) > override def flatten[T <: MSequitor[MSequitor[A]]]( bsq : T ) > : MSequitor[A] = empty.flatten( bsq ) > } > > -- > L.G. Meredith > Managing Partner > Biosimilarity LLC > 1219 NW 83rd St > Seattle, WA 98117 > > +1 206.650.3740 > > http://biosimilarity.blogspot.com > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---