Created
July 6, 2020 12:15
-
-
Save jseteny/483a40d8805a23ea81488ce8e5f7a754 to your computer and use it in GitHub Desktop.
Simplistic reproduction of https://github.com/scala/scala/blob/v2.13.3/src/library/scala/collection/immutable/List.scala
This file contains hidden or 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
{ | |
trait QList[+A]{ | |
def ::[B >: A](head: B): QList[B] = new ::(head, this) | |
} | |
case class ::[+A](head: A, tail: QList[A]) extends QList[A] | |
object QNil extends QList[Nothing] | |
} | |
// defined trait QList | |
// defined class :: | |
// defined object QNil | |
1 :: QNil | |
// res9: QList[Int] = 1 :: ammonite.$sess.cmd8$QNil$@f2d890c | |
1 :: QNil match { | |
case QNil => 1 | |
case _ => 0 | |
} | |
// res10: Int = 0 | |
QNil match { | |
case QNil => 1 | |
case _ => 0 | |
} | |
// res11: Int = 1 | |
2 :: QNil match { | |
case a::_ => a | |
case _ => 0 | |
} | |
// res12: Int = 2 | |
1::2::3::QNil | |
// res13: QList[Int] = 1 :: 2 :: 3 :: ammonite.$sess.cmd8$QNil$@f2d890c | |
"1"::"2"::"3"::QNil | |
// res14: QList[String] = "1" :: "2" :: "3" :: ammonite.$sess.cmd8$QNil$@f2d890c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To try it yourself there is a so called one-click Scala install option to consider:
https://www.scala-lang.org/2020/06/29/one-click-install.html
... will install all the following software, if not yet installed:
a JDK
the build tools sbt and mill
the Ammonite enhanced REPL
scalafmt, the Scala formatter
the coursier CLI, to install further Scala-based applications
the scala and scalac command-line tools
With all those installed, we are ready to go! Later, cs update can be used to update the installation.
For power users, the cs setup command offers more configuration options, such as a non-interactive mode.
If you need one or more very simple VM for your experiment(s) you may try:
https://multipass.run