Skip to content

Instantly share code, notes, and snippets.

@mads-hartmann
Created September 4, 2013 12:44
Show Gist options
  • Save mads-hartmann/6436434 to your computer and use it in GitHub Desktop.
Save mads-hartmann/6436434 to your computer and use it in GitHub Desktop.
Attempt at implementing `++` for a statically sized list
object NList {
import Nat._
sealed trait NList[L <: Nat, A] {
def ++[B >: A, M <: Nat](other: NList[M, B])
(implicit sum: Plus[L, M]): NList[sum.Out, B]
}
case object NNil extends NList[Zero, Nothing] {
/*
[error] found : NList.NList[M,B]
[error] required: NList.NList[sum.Out,B]
[error] (implicit sum: Plus[Zero, M]): NList[sum.Out, B] = other
[error] ^
*/
def ++[B >: Nothing, M <: Nat](other: NList[M, B])
(implicit sum: Plus[Zero, M]): NList[sum.Out, B] = other
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment