HiveBrain v1.2.0
Get Started
← Back to all entries
principleMinor

What's the advantage of "value restriction" over its alternatives?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
thewhatrestrictionvaluealternativesitsadvantageover

Problem

What is the motivation to pick "value restriction" over other candidates?

Examples of alternatives:

-
Enclosing pureness into the function type, for example:

pure_function : x -> x
impure_function : x => x


-
Polymorphism by name (call by name) as in Xavier Leroy, 1993

Xavier Leroy, 1993. Polymorphism by name for references and continuations. In 20th symposium Principles of Programming Languages, pages 220-231. ACM Press, 1993.

Solution

I'm sure that this isn't the only advantage, but I think the primary advantage is simplicity. This is even identified in the original paper introducing the value restriction: previous solutions all existed, but the complexity of annotations made them undesirable.

  • The majority of value that people want to give polymorphic types are functions, which are values, and you can "fake it" with thunks for anything that isn't a value.



  • The language of types is unchanged, so it's easier for the programmer to use. There is no need for extra annotations or types. The users



In "real world" languages, the solutions falls into two categories. ML-style languages use the value restriction, and Haskell-style language use purity and monadic effects. Rust even uses a more restrictive version of the value restriction, where only top-level functions can be polymorphic.

As is common with PL research, there may be many theoretically sound solutions which don't gain traction in popular languages because of their difficulty or awkwardness of use.

Context

StackExchange Computer Science Q#79453, answer score: 5

Revisions (0)

No revisions yet.