You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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 notactually 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.
The text was updated successfully, but these errors were encountered: