Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Singleton Types #118

Open
skaller opened this issue Jul 31, 2018 · 0 comments
Open

Singleton Types #118

skaller opened this issue Jul 31, 2018 · 0 comments
Assignees

Comments

@skaller
Copy link
Member

skaller commented Jul 31, 2018

A way to specify a singleton type would be useful. A singleton type is a type with
only one possible value, and therefore all singletons are units.

When Felix has a variable or expression of type unit, it can be replaced
by a unit value, in particular functions returning unit are useless
and applications of them can be replace by unit value.

It would useful to have this optimisation for all singletons, however there
is very useful derived property that solves a nasty problem.

Consider a var (addressble store) of a singleton type. In effect, this variable
is a constant. Even if the the address is taken and a value stored in it,
its value can't change because there's only one value. So if T is a singleton
type then saying

var x : T = tval;

effectively makes x a constant. It isn't immutable but no mutation can change it.
This solves the problem that in a loop, a val, although not addressable,
can be initialised to a different value each iteration, so that a val is not
actually a constant: the user cannot modify it, but it isn't immutable either.
More precisely val's only allow a single assignment, but the value assigned
can differ if control flow executes it more than once. So although vals were
originally intended to just be names of values .. they're actually variables.

@skaller skaller self-assigned this Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant