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
package progscala3.erased | |
import scala.language.experimental.erasedDefinitions | |
@main def Main() = | |
// Use the +: methods to construct sequences. | |
val nes1 = "one" +: EmptySeq | |
val nes2 = "two" +: nes1 | |
val nes3 = "three" +: nes2 |
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
package progscala3.erased | |
import scala.annotation.implicitNotFound | |
import scala.language.experimental.erasedDefinitions | |
sealed trait Emptiness | |
final class Empty extends Emptiness | |
final class NotEmpty extends Emptiness | |
@implicitNotFound("The seq must be empty") |
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
// Requires a snapshot or nightly build of Scala | |
val scala3 = "3.1.3-RC1-bin-SNAPSHOT" | |
lazy val root = project | |
.in(file(".")) | |
.settings( | |
name := "erased-feature-example", | |
description := "An example of the experimental 'erased' feature.", | |
version := "0.0.1", | |
scalaVersion := scala3, |
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
package progscala3.rounding.saferexceptions | |
import java.io.{IOException, File} | |
import scala.annotation.experimental | |
import language.experimental.saferExceptions | |
@experimental | |
object SaferExceptionsNested: | |
def main(fileNames: Array[String]): Unit = | |
fileNames.foreach { fileName => | |
try |
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
package progscala3.rounding.saferexceptions | |
import java.io.{IOException, File} | |
import scala.annotation.experimental | |
// Enable safer exceptions | |
import language.experimental.saferExceptions | |
@experimental | |
object SaferExceptions: | |
def main(fileNames: Array[String]): Unit = | |
fileNames.foreach { fileName => |
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
package progscala3.rounding.saferexceptions | |
import java.io.{IOException, File} | |
import scala.annotation.experimental | |
// Enable safer exceptions | |
import language.experimental.saferExceptions | |
/** | |
* Currently as written, this file doesn't compile using Scala 3.1. | |
* Also, the object needs the `@experimental` annotation in order to use this feature. | |
*/ |
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
package polyglotprogramming.messaging.v4 | |
import polyglotprogramming.messaging.* | |
import polyglotprogramming.messaging.v4.given | |
object Processor: | |
def apply[IM <: IncomingMessage](message: IM)(using handler: MessageHandler[IM]): OutgoingMessage = | |
handler(message) | |
/** | |
* Add a new message type! |
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
package polyglotprogramming.messaging.v3 | |
import polyglotprogramming.messaging.* | |
trait MessageHandler[IM <: IncomingMessage]: | |
final def apply(message: IM): OutgoingMessage = | |
println(s"Received message: $message") | |
process(message) | |
protected def process(message: IM): OutgoingMessage |
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
package polyglotprogramming.messaging.v2 | |
import polyglotprogramming.messaging.* | |
import polyglotprogramming.messaging.v2.given | |
object Processor: | |
def apply[IM <: IncomingMessage](message: IM)(using handler: MessageHandler[IM]): OutgoingMessage = | |
handler(message) | |
@main def Messaging() = | |
println(Processor(Start("start"))) |
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
package polyglotprogramming.messaging.v2 | |
import polyglotprogramming.messaging.* | |
trait MessageHandler[IM <: IncomingMessage]: | |
def apply(message: IM): OutgoingMessage = | |
println(s"Received message: $message") | |
Succeeded(s"Successfully processed $message") | |
given MessageHandler[Start]() | |
given MessageHandler[DoWork1]() |
NewerOlder