logoalt Hacker News

antonvs • yesterday at 11:05 PM • 1 reply • view on HN

> These are the constructs we manipulate in our programs, things like 1, 2, True, "hello", etc… In functional programming contexts, they're also called "terms."

This is not correct. Terms are syntactic expressions in a program. For example, 1+2 is a term, but it’s not a value. At runtime, it evaluates to 3. As such, some terms correspond directly to values - like 1 - but other terms represent computations that will be performed at runtime.

tl;dr: terms are a syntactic concept, values are a runtime concept. Terms evaluate to values.


Replies

antonvs • yesterday at 11:38 PM

Following on from the above, this statement is also incomplete at best:

> Types are groups of related values.

This is an operational perspective which misses one of the most important aspects of types: in a statically typed language, types are a way to classify terms, i.e. they're not just about values.

As an example of why this distinction matters, consider this expression: 1 + "hello". In most statically typed languages, this will be rejected at compile time. It doesn't have to be evaluated (i.e. at runtime) to be rejected - it's invalid because the types of the terms - 1 and "hello" - aren't compatible.

This compile-time rejection is only possibly because types apply to terms, and terms aren't values. This is critical to the usefulness of statically-typed languages - without this, they'd have to run the program to detect type errors.

Benjamin Pierce's book "Types and Programming Languages" has some great coverage of this topic.

➕ show 1 reply