Skip to content

earldouglas/linear-scala

Repository files navigation

Build Status Release Artifacts

linear-scala

linear-scala adds support for linear types in Scala via a custom Scalafix linter.

Setup

project/plugins.sbt:

addSbtPlugin("com.earldouglas" % "sbt-linear-scala" % "0.0.3")

Usage

Mix in the Linear interface to prevent values from being under/over-used.

import com.earldouglas.linearscala.Linear

case class Box(value: Int) extends Linear

Scalafix finds values that are never used:

trait UnusedField {
  val box: Box = Box(42) // error: box is never used
}

trait UnusedParameter {
  def foo(x: Box, y: Box): Int = // error: y is never used
    x.value
}

Scalafix also finds values that are used multiple times:

trait FieldUsedTwice {
  val box: Box = Box(42)
  println(box) // error: box is used twice
  println(box) // error: box is used twice
}

See the tests in input/src/main/scala/fix/ for more examples.

References

Linear Types

About

Linear types in Scala

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy