Supported Scala Features
Scalus compiles Scala code to Untyped Plutus Core (UPLC), a minimalist lambda calculus designed for secure blockchain execution. This constraint means only a subset of Scala’s feature set is supported—those that can be efficiently and deterministically translated to UPLC.
The compilation process transforms your Scala code into an intermediate representation before generating the final UPLC that runs on Cardano. UPLC’s deliberately limited nature (optimized for security and determinism) excludes many high-level language features.
Supported Features
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
Unsupported Features
vars andlazy vals - use immutablevaldeclarations insteadwhileloops - use recursion or higher-order functions likefold- classes, inheritance and polymorphism aka virtual dispatch
- you can’t use
isInstanceOfor runtime type checks - use sealed traits with enums or case classes for polymorphic data
- you can’t use
- pattern matching with guards - move guard conditions to the right-hand side with
if-then-else - pattern matching on multiple constructors (
case A | B => ...) - use separate cases - pattern matching using type ascriptions (
case x: BigInt => ...) - pattern match on structure instead try-catchexpressions - useOption,Either, or error handling patterns instead- overloaded functions - each function must have a unique name
- mutually recursive functions - functions cannot call each other recursively
Last updated on