Supported Scala features
Scalus compiles Scala code to Untyped Plutus Core (UPLC), which is a minimalist form of lambda calculus designed for blockchain execution. This fundamental constraint means that only a subset of Scala’s rich feature set can be supported.
The compilation process transforms your Scala code into an intermediate representation before generating the final UPLC that runs on the Cardano blockchain. Due to UPLC’s deliberately limited nature (optimized for security and determinism), many high-level Scala features cannot be directly translated.
What Scala features are supported?
Below is a comprehensive list of what Scala features are currently supported in Scalus:
- simple
vals anddefs of supported built-in types or case classes/enums - lambda expressions
- recursive functions
- passing/returning functions as arguments (higher-order functions)
if-then-elseexpressions- simple
matchexpressions on case classes and enums- only simple bindings are supported like
case Costr(field, other) => ...
- only simple bindings are supported like
givenarguments andusingclausesthrowexpressions but notry-catchexpressions- built-in functions and operators
- simple data types: case classes and enums
inlinevals, functions and macros in general- implicit conversions
- opaque types (non top-level) and type aliases
- extension methods
- tuples
- value destructuring in vals:
val Some((a, b)) = optionOfTuple
Scala features that are not supported
vars andlazy valswhileloops- classes, inheritance and polymorphism aka virtual dispatch
- you can’t use
isInstanceOf
- you can’t use
- pattern matching with guards
- pattern matching on multiple constructors (
case A | B => ...) - pattern matching using type ascriptions (
case x: BigInt => ...) try-catchexpressions- overloaded functions
- mutually recursive functions
Last updated on