A Common Lisp library for defining and operating on algebraic data types with pattern matching, inspired by functional languages.
CL-ALGEBRAIC-DATA-TYPE is a Common Lisp library that implements algebraic data types and pattern matching, inspired by functional languages like Haskell and Standard ML. It allows developers to define custom data types with constructors and perform exhaustive pattern matching on them, bringing functional programming idioms to Common Lisp. The library addresses the need for more structured and type-safe data modeling in Lisp's dynamic environment.
Common Lisp developers interested in functional programming paradigms, those building applications that benefit from algebraic data types and pattern matching, and programmers transitioning from statically-typed functional languages to Lisp.
Developers choose CL-ALGEBRAIC-DATA-TYPE for its straightforward integration with Common Lisp, providing algebraic data types without the overhead of a full static type system like Coalton. Its unique selling point is the balance between functional programming expressiveness and Lisp's dynamic nature, with features like mutable ADTs and readable printing.
Algebraic data types in Common Lisp
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The defdata macro allows defining ADTs with multiple constructors (unary, binary, nullary), similar to Haskell, as shown with the maybe and liszt examples for clear data modeling.
Match provides compile-time warnings for non-exhaustive cases, such as when the polar case is omitted in point matching, enhancing code safety and reducing errors.
Optional mutability with :mutable t and set-data enables efficient in-place updates, useful for performance-critical code, demonstrated with the mirror-point! function.
The :include option lets ADTs inherit constructors from others, promoting code reuse, as seen with fuzzy-bool extending bool to add a fuzzy constructor.
get-constructors returns constructor names and arities dynamically, allowing for introspection and meta-programming, useful in debugging or dynamic systems.
As admitted in the FAQ, there's no support for parametric ADTs, limiting the ability to define generic, reusable data structures like in Haskell.
Deeper pattern matching on nested ADTs isn't implemented (patches welcome), restricting complex destructuring patterns common in functional programming.
Built on Common Lisp's dynamic system, it lacks compile-time type checking, making it less suitable for strict type safety compared to static alternatives like Coalton.