| @@ -0,0 +1,27 @@ |
| 1 | +# ADR 0063: No ML functors, for now |
| 2 | + |
| 3 | +**Status:** Proposed (2026-10-27, issue #217); needs the project owner's decision and engineering review (#44). |
| 4 | + |
| 5 | +## Context |
| 6 | + |
| 7 | +A review of Louise (issue #217) noted that it has no ML-style module system: no signatures, and no functors, which are modules parameterised by other modules. It called functors "the one Haskell/OCaml feature a domain modeller will miss most", and a route to zero-cost abstractions. |
| 8 | + |
| 9 | +What Louise has instead, for the same jobs: |
| 10 | +- **Abstraction over an implementation:** traits with several parameters and higher kinds ([ADR 0018](0018-multi-parameter-traits-and-hkt.md)), and associated types ([ADR 0047](0047-associated-types.md)). `std/collection.lse` has a `Collection` trait with a `type Elem`, over `List`, `Array` and others. |
| 11 | +- **Hiding a representation:** opaque types ([ADR 0033](0033-opaque-types.md)). A module exports a type without its constructors, and keeps its invariants. |
| 12 | +- **Swapping a dependency:** effects and their handlers ([ADR 0010](0010-lexical-handlers.md)). A function names the operations it needs, and the caller installs an implementation. toki2, the first real application, writes every port (event store, sessions, password hashing) this way. It has test, development and production implementations, and no functor. |
| 13 | +- **Zero cost:** trait calls on known types are specialised ([ADR 0013](0013-numeric-code.md)). A functor's main performance argument is already met. |
| 14 | + |
| 15 | +## Decision |
| 16 | + |
| 17 | +Louise does not add signatures or functors now. |
| 18 | + |
| 19 | +- **Two module systems are one too many.** Traits, opaque types and effects already decide what code may see and what it depends on. Functors would add a second way to do each, with different rules, and every library would have to choose. |
| 20 | +- **No program has needed one.** toki2 (event sourcing, three domains, ports, read models) and the standard library were written without missing them. |
| 21 | +- **The cost is large.** Signatures, functor application, and the generativity of the types a functor makes would touch name resolution, the type checker, separate checking of packages and the language server. It would be the largest change since the parens-free syntax ([ADR 0062](0062-parens-free-functions.md)). |
| 22 | + |
| 23 | +## Consequences |
| 24 | + |
| 25 | +- One known gap remains. A trait has one implementation per type (coherence), so two orderings of the same type need a wrapper type, as in Haskell (`newtype Down`). An ML functor would make two `Set` modules instead. |
| 26 | +- **When to revisit:** when a real program needs several implementations of one interface at the type level that a wrapper type can't express cleanly, or a package needs to be checked against an interface without its implementation. |
| 27 | +- Issue #217's point is answered here, not by a feature. |