evhub / evhub/coconut

Are these really algebraic data types?

Open
#418 13 comments 1 reaction 0 assignees View on GitHub
documentation question
Dominant language
Python
Stars
4.4k
Forks
142
PR merge metrics
No merged PRs in 30d

Description

Coconut's [documentation for the `data` keyword](http://coconut.readthedocs.io/en/master/DOCS.html#data) states that it lets you create immutable ADTs. I see a nice concise language for creating immutable product types, but for it to truly offer an algebra, I believe[1] it would have to offer sum types.

The `data` keyword lets us multiply two types. For instance, we can multiply the `int` type with the `string` type by making a type `T` that has two fields, one of them an int and the other a string. In every instance of `T` both fields are mandatory.

If we could add the types `int` and `string`, it would mean we could create a new type `T` for which every instance could include either a string or an int, without including the other. That is, the type T would offer multiple constructors, which when called create instances of T with different fields.

Right?

---

[1] My understanding* of the term "algebra" is that it implies both addition and multiplication, and that for types, "multiplication" is the conjunction (`and`) operator, while "addition" is the disjunction (`or`) operator.

That interpretation seemed very weird to me until I noticed its implications for the size of the sets in question: If type A has 5 members and type B has 6, then their sum has 11 members, while their product has 30.

Sorry if I'm stating things you already know; I'm trying to keep a wide potential readership.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.