Desugared
Desugared refers to code that has been transformed from its syntactic sugar into a more explicit, lower‑level form using primitive constructs of the language. Syntactic sugar comprises language features that make code easier to read or write but have the same semantics as more explicit constructs.
Desugaring is typically performed by a compiler or preprocessor as part of a lowering or desugaring phase.
Examples of desugaring across languages include:
- Haskell: A do-block is desugared into a sequence of monadic binds using the (>>=) operator and return.
- Scala: For-comprehensions desugar into combinations of flatMap, map, and withFilter, yielding the same semantics as the
- JavaScript: Destructuring assignments and certain arrow-function forms can be desugared into explicit variable assignments and function
- Other languages: Features such as pattern matching, optional chaining, or range expressions can also be desugared
Note on semantics: Desugaring preserves the program’s semantics, though it can affect source-level diagnostics and debugging