Created
August 29, 2015 03:46
-
-
Save xuwei-k/88acf7008486e27ea62c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package multimplicit | |
sealed abstract class Multimplicit extends Product with Serializable | |
final case class ::[+H, +T <: Multimplicit](head : H, tail : T) extends Multimplicit { | |
override def toString = head match { | |
case _: ::[_, _] => "("+head+") :: "+tail.toString | |
case _ => head+" :: "+tail.toString | |
} | |
} | |
object :: { | |
implicit def instance[H, T <: Multimplicit](implicit h: H, t: T): H :: T = | |
::(h, t) | |
} | |
sealed abstract class MNil extends Multimplicit { | |
override def toString = "HNil" | |
def ::[H](h : H) = multimplicit.::(h, this) | |
} | |
case object MNil extends MNil { | |
implicit val self: this.type = this | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment