Skip to content

Commit b612f15

Browse files
Make Enso "conversion and equality oriented" language (#14133)
Enso, at it roots, is a **conversion oriented language**. Enso supports flexible definitions of conversions of values of a type to another. To stress the importance of conversions in usage of the Enso language, there is `Any.to target_type` method available on any value in the Enso system that allows to _morph and view any object as a different type_ easily when such a conversion is available. In addition to that Enso is **structured equality oriented language**. There is `Any.==` operator that allows any two values to be compared for equality. The comparison is based on structure - e.g. two instances of the same atom with equal fields are the same. Enso provides such a _structured equality_ implementation to every user defined type automatically, yet it also offers more complex equality handling when needed (via `Comparable` type). Enso is **conversion and** (structured) **equality oriented language**. That fact is stressed by the shape of its root type `Any`. It exposes just `.to`, `==` and `!=` operations. # Important Notes - To fulfill the promise of Enso being **conversion and equality oriented language** - this PR proposes to turn `Nothing` related methods into _extension methods_ - e.g. to move them out of `Any` type into `Nothing` type - the change is supposed to be compatible for everyone using `from Standard.Base import all` - this PR is the final step finishing the work previously started by - #14004 - #14003 - #13978 - #14017 - #14050 - in the tradition of those PRs let's argue: - it is better to be somebody, or at least anybody - nobody wants to feel like `Nothing` - hence we don't want Enso to feel like "nothing oriented language" - as such `Nothing` related methods should be provided only as extension methods! - on a more technical note: `obj.is_nothing.not` can actually be written as `obj!=Nothing`, not sure why we prefer the former (and longer) variant? Maybe some FP bias!?
1 parent 94f4b96 commit b612f15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+149
-133
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
#### Enso Language & Runtime
4646

47+
- [Enso is "conversion and equality oriented" language][14133]
4748
- [Moving >, >=, <, <= to types where such operators make sense][14017]
4849
- [Moving warning releated methods outside of `Any`][13978]
4950
- [Moving error relelated methods outside of `Any`][14003]
@@ -55,6 +56,7 @@
5556
expressions][13914]
5657
- [Autocompletion for table expression operators and operands][13917]
5758

59+
[14133]: https://github.com/enso-org/enso/pull/14133
5860
[14017]: https://github.com/enso-org/enso/pull/14017
5961
[14003]: https://github.com/enso-org/enso/pull/14003
6062
[13978]: https://github.com/enso-org/enso/pull/13978

distribution/lib/Standard/Base/0.0.0-dev/docs/api/Any.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,4 @@
33
- type Any
44
- != self that:Standard.Base.Any.Any -> Standard.Base.Any.Any
55
- == self that:Standard.Base.Any.Any -> Standard.Base.Any.Any
6-
- if_not_nothing self ~action:Standard.Base.Any.Any -> Standard.Base.Any.Any
7-
- if_nothing self ~other:Standard.Base.Any.Any -> Standard.Base.Any.Any
8-
- is_nothing self -> Standard.Base.Any.Any
9-
- map_nothing self f:Standard.Base.Any.Any -> Standard.Base.Any.Any
106
- to self target_type:Standard.Base.Any.Any -> Standard.Base.Any.Any

distribution/lib/Standard/Base/0.0.0-dev/docs/api/Nothing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
- if_not_nothing self ~action:Standard.Base.Any.Any -> Standard.Base.Any.Any
66
- if_nothing self ~function:Standard.Base.Any.Any -> Standard.Base.Any.Any
77
- is_nothing self -> Standard.Base.Any.Any
8+
- Standard.Base.Any.Any.if_not_nothing self ~action:Standard.Base.Any.Any -> Standard.Base.Any.Any
9+
- Standard.Base.Any.Any.if_nothing self ~other:Standard.Base.Any.Any -> Standard.Base.Any.Any
10+
- Standard.Base.Any.Any.is_nothing self -> Standard.Base.Data.Boolean.Boolean
11+
- Standard.Base.Any.Any.map_nothing self f:Standard.Base.Any.Any -> Standard.Base.Any.Any

distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import project.Meta
2-
import project.Nothing.Nothing
3-
from project.Data.Boolean import Boolean, False, True
4-
from project.Data.Ordering import all
5-
from project.Data.Range.Extensions import all
6-
from project.Function import const
1+
from project.Data.Boolean import Boolean
72
import project.Errors.Common.No_Such_Conversion
83
from project.Metadata import Widget
94

@@ -149,73 +144,3 @@ type Any
149144
`Any.==`.
150145
!= : Any -> Boolean
151146
!= self that = (self == that).not
152-
153-
## ---
154-
group: Logical
155-
icon: metadata
156-
---
157-
Checks if the type is an instance of `Nothing`.
158-
Nothing in Enso is used as a universal value to indicate the lack of
159-
presence of a value. This function is primarily useful in the IDE.
160-
161-
## Examples
162-
### Checking if the value 1 is nothing.
163-
164-
```
165-
1.is_nothing
166-
```
167-
is_nothing : Boolean
168-
is_nothing self = False
169-
170-
## ---
171-
group: Logical
172-
icon: operators
173-
---
174-
If `self` is Nothing then returns `other`.
175-
176-
## Examples
177-
### If the value "Hello" is nothing return "".
178-
179-
```
180-
"Hello".if_nothing ""
181-
```
182-
if_nothing : Any -> Any
183-
if_nothing self ~other =
184-
const self other
185-
186-
## ---
187-
group: Logical
188-
icon: operators
189-
---
190-
If `self` is Nothing then returns Nothing, otherwise returns the result of
191-
running the provided `action`.
192-
193-
## Examples
194-
### Transform a value only if it is not nothing.
195-
196-
```
197-
my_result.if_not_nothing <| my_result + 1
198-
```
199-
if_not_nothing : Any -> Any
200-
if_not_nothing self ~action = action
201-
202-
## ---
203-
icon: column_add
204-
---
205-
Applies the provided function to `self` unless `self` is `Nothing`, which
206-
is returned unchanged.
207-
208-
## Arguments
209-
- `f`: The function to apply to `self` if `self` is not `Nothing`.
210-
211-
## Examples
212-
### Applying a function over a value 10.
213-
214-
```
215-
10.map_nothing *2
216-
```
217-
map_nothing : (Any -> Any) -> Any | Nothing
218-
map_nothing self f = case self of
219-
Nothing -> Nothing
220-
a -> f a
221-

distribution/lib/Standard/Base/0.0.0-dev/src/Data/Filter_Condition.enso

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import project.Data.Vector.Vector
99
import project.Errors.Common.Missing_Argument
1010
import project.Internal.Predicate_Helpers
1111
import project.Meta
12-
import project.Nothing.Nothing
12+
from project.Nothing import all
1313
from project.Data.Boolean import Boolean, False, True
1414
from project.Data.Filter_Condition.Filter_Condition import all
1515
from project.Data.Text.Extensions import all

distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import project.Errors.Common.Index_Out_Of_Bounds
2121
import project.Errors.Common.Not_Found
2222
import project.Errors.Empty_Error.Empty_Error
2323
import project.Meta
24-
import project.Nothing.Nothing
2524
import project.Panic.Panic
25+
from project.Nothing import all
2626
from project.Data.Boolean import Boolean, False, True
2727
from project.Data.List.List import Cons, Nil
2828
from project.Internal.Predicate_Helpers import unify_condition_or_predicate, unify_condition_predicate_or_element

distribution/lib/Standard/Base/0.0.0-dev/src/Data/Locale.enso

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import project.Data.Vector.Vector
66
import project.Meta
77
import project.Metadata.Display
88
import project.Metadata.Widget
9-
import project.Nothing.Nothing
109
import project.Panic.Panic
10+
from project.Nothing import all
1111
from project.Data.Text.Extensions import all
1212
from project.Metadata.Choice import Option
1313

distribution/lib/Standard/Base/0.0.0-dev/src/Data/Numbers.enso

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import project.Errors.Common.Incomparable_Values
1010
import project.Errors.Common.Unsupported_Argument_Types
1111
import project.Errors.Illegal_Argument.Illegal_Argument
1212
import project.Internal.Rounding_Helpers
13-
import project.Nothing.Nothing
1413
import project.Panic.Panic
14+
from project.Nothing import all
1515
from project.Data.Boolean import Boolean, False, True
1616
from project.Internal.Number_Builtins import all
1717
from project.Internal.Ordering_Helpers import Positive_Integer_Comparator

distribution/lib/Standard/Base/0.0.0-dev/src/Data/Range.enso

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import project.Errors.Empty_Error.Empty_Error
1111
import project.Errors.Illegal_Argument.Illegal_Argument
1212
import project.Errors.Illegal_State.Illegal_State
1313
import project.Function.Function
14-
import project.Nothing.Nothing
1514
import project.Panic.Panic
15+
from project.Nothing import all
1616
from project.Data.Boolean import Boolean, False, True
1717
from project.Error import all
1818
from project.Internal.Predicate_Helpers import unify_condition_or_predicate

distribution/lib/Standard/Base/0.0.0-dev/src/Data/Read/Return_As.enso

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import project.Function.Function
1111
import project.Meta
1212
import project.Metadata.Display
1313
import project.Metadata.Widget
14-
import project.Nothing.Nothing
1514
import project.Panic.Panic
15+
from project.Nothing import all
1616
from project.Data.Boolean import False, True
1717
from project.Metadata.Choice import Option
1818
from project.Metadata.Widget import Single_Choice

0 commit comments

Comments
 (0)