alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (tcpoly_ticket2096.scala)

This example Scala source code file (tcpoly_ticket2096.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

a, a, c, c, int, mbrace, mbrace, mbraceseq, mbracesequitor, msequitor, msequitor, seq, t

The Scala tcpoly_ticket2096.scala source code

// smallest expression of monad i can find
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 iterator = a_.iterator
 override def apply( n : Int ) = a_.apply( n )
}

//  type arguments [MSequitor,A] do not conform to trait MBraceSeq's type parameter bounds [C[_] <: MBrace[C,A] with Seq[A],A]
// 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 )
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala tcpoly_ticket2096.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.