Skip to content

Instantly share code, notes, and snippets.

@johnynek
johnynek / dotty_list.scala
Last active January 12, 2020 13:43
Implementation of linked list using dotty features (opaque type, union types, extension methods, type lambda).
// unfortunately
// opaque type Fix[F[_]] = F[Fix[F]]
// won't work (no recursion in opaque type), but this implementation is safe, but scary due to asInstanceOf
object FixImpl {
type Fix[F[_]]
inline def fix[F[_]](f: F[Fix[F]]): Fix[F] = f.asInstanceOf[Fix[F]]
inline def unfix[F[_]](f: Fix[F]): F[Fix[F]] = f.asInstanceOf[F[Fix[F]]]
}