Skip to content

Instantly share code, notes, and snippets.

@goral09
Last active October 12, 2016 10:27
Show Gist options
  • Save goral09/fd06d08ad867fc03770aad1e3dc6f5af to your computer and use it in GitHub Desktop.
Save goral09/fd06d08ad867fc03770aad1e3dc6f5af to your computer and use it in GitHub Desktop.
def mdropFirstE[T0](xs: MList { type T = T0 })
: MList { type T = T0 } =
xs.uncons match {
case None => MNil()
case Some(ml) => ml.tail
}
def pdropFirst[T](xs: PList[T]): PList[T] = xs match {
case PNil() => PNil()
case PCons(_, t) => t
}
def toMlist[T0](xs: PList[T0]): MList { type T = T0 } =
xs match {
case PNil() => MNil[T0]()
case PCons(el, t) => MCons(el, toMlist(t))
}
def toPlist[T0](xs: MList { type T = T0 }): PList[T0] =
xs.uncons match {
case None => PNil[T0]()
case Some(cons) => PCons(cons.head, toPlist(cons.tail))
}
def pdropFirstWithE[T](xs: PList[T]): PList[T] =
toPlist[T](mdropFirstE(toMlist[T](xs)))
def mdropFirstEwithP(xs: MList): MList =
toMlist(pdropFirst[xs.T](toPlist(xs)))
val plist = PCons(10, PCons(20, PNil()))
val mlist = MCons[Int](10, MCons(20, MNil()))
mdropFirstEwithP(mlist)
pdropFirstWithE(plist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment