4 ms·
The Haskell 98 report mentions a strange type system restriction. It is called the monomorphism restriction and concerns making decisions about types during inf
by panic 10y ago
The Haskell 98 report mentions a strange type system restriction. It is called the monomorphism restriction and concerns making decisions about types during inference. It sounds like abstract nonsense, but makes sense in the context of category theory, where morphisms are a generalization of functions and monomorphisms in particular correspond to injective functions. Regardless of its cryptic name, it solves a practical problem: it prevents ambiguous types from appearing.
The "monomorphism" in "monomorphism restriction" isn't the term from category theory: it's just the opposite of "polymorphism". You can read more about the details of the restriction and why it exists here: https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-930004.5.5 https://www.haskell.org/onlinereport/haskell2010/haskellch4....
- pklausler 10y agoI don't really mind the monomorphism restriction for definitions whose types aren't functions, but it bugs me quite a bit that a function defined in terms of pattern matching won't trip over the monomorphism restriction but the otherwise-equivalent definition in terms of lambda can.