Last active
May 25, 2024 10:19
-
-
Save dacr/4b10cd395025dde86b350a6e90f28678 to your computer and use it in GitHub Desktop.
scala3 feature examples - literal types / published by https://github.com/dacr/code-examples-manager #4335490b-72fe-46b6-95cf-7a84023569f6/cbc31bd2af713a0ec8e1aa6ad58b4b97024552d1
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
// summary : scala3 feature examples - literal types | |
// keywords : scala3, tutorial | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 4335490b-72fe-46b6-95cf-7a84023569f6 | |
// created-on : 2021-03-25T11:22:13+01:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
//> using scala "3.4.2" | |
val pi: 3.14157 = 3.14157 | |
val _: 3.14157 = 3.14 // compile error ! | |
val choice0: 1|2|3 = 1 | |
val choice1: 1|2|3 = 4 // compile error ! | |
val choice2: Option["A"|"B"] = None | |
val choice3: Option["A"|"B"] = Some("A") | |
val choice4: Option["A"|"B"] = Some("C") // compile error ! | |
type Choice="A"|"B"|"C" | |
val myChoice:Choice = "A" | |
val myChoice:Choice = "D" // compile error ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment