Tidy Standard.Base Part 2 of n... (#3889)

- Moved static methods into `Locale` type. Publishing type not module.
- Stop publishing `Nil` and `Cons` from `List`.
- Tidied up `Json` and merged static in to type. Sorted out various type signatures which used a `Constructor`. Now exporting type and extensions.
- Tidied up `Noise` and merge `Generator` into file. Export type not module.
- Moved static method of `Map` into type. Publishing type not module.

# Important Notes
- Move `Text.compare_to` into `Text`.
- Move `Text.to_json` into `Json`.
This commit is contained in:
James Dunkerley 2022-11-19 08:01:45 +00:00 committed by GitHub
parent 5b6fd74929
commit 99bacc5c06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
62 changed files with 1069 additions and 1097 deletions

View File

@ -29,7 +29,7 @@ component-groups:
- Standard.Base.Network.Http.options
- Parse:
exports:
- Standard.Base.Data.Json.parse
- Standard.Base.Data.Json.Json.parse
- Standard.Base.Data.Text.Regex.compile
- Standard.Base.Data.Text.Regex.escape
- Standard.Base.Data.Text.Regex.from_flags

View File

@ -2,10 +2,9 @@ import project.Data.Ordering.Ordering
import project.Data.Pair.Pair
import project.Data.Range
import project.Data.Text.Text
import project.Data.Text.Extensions
import project.Nothing.Nothing
import project.Meta
import project.Data.Json
from project.Data.Json import all
from project.Data.Boolean import Boolean, True, False
from project.Error.Common import Error, dataflow_error_handler

View File

@ -1,53 +1,48 @@
from Standard.Base import all hiding Parse_Error_Data, Array, Boolean, Number
import Standard.Base
from Standard.Base import all
import project.Data.Map.No_Value_For_Key
import Standard.Base.Data.Json.Internal
## A smart constructor, building an object representation based on a vector
of key-value pairs.
Arguments:
- contents: A vector of key-value pairs.
All values used as keys must define a `to_json_key : Text` method.
> Example
The following code returns a JSON object, that after serialization becomes
{ "foo": 533, "bar": false }
import Standard.Base.Data.Json
example_from_pairs = Json.from_pairs [["foo", 533], ["bar", False]]
from_pairs : Vector -> Object
from_pairs contents =
fs = contents.fold Map.empty map-> kv_pair->
key = kv_pair . at 0 . to_json_key
val = kv_pair . at 1 . to_json
map.insert key val
Object fs
## Parses an RFC-8259 compliant JSON text into a `Json` structure.
Arguments:
- json_text: The RFC-8259-compliant JSON text.
> Example
Convert some text representing a JSON object into JSON.
import Standard.Base.Data.Json
example_parse = Json.parse '{ "a": 1 }'
parse : Text -> Json ! Parse_Error
parse json_text =
Panic.catch_java Any (Internal.parse_helper json_text) java_exception->
Error.throw (Parse_Error_Data java_exception.getMessage)
# TODO Dubious constructor export
from project.Data.Json.Json import all
from project.Data.Json.Json export all
import project.Data.Json.Internal
## Represents a JSON structure.
type Json
## A smart constructor, building an object representation based on a vector
of key-value pairs.
Arguments:
- contents: A vector of key-value pairs.
All values used as keys must define a `to_json_key : Text` method.
> Example
The following code returns a JSON object, that after serialization becomes
{ "foo": 533, "bar": false }
import Standard.Base.Data.Json.Json
example_from_pairs = Json.from_pairs [["foo", 533], ["bar", False]]
from_pairs : Vector -> Json
from_pairs contents =
fs = contents.fold Map.empty map-> kv_pair->
key = kv_pair . at 0 . to_json_key
val = kv_pair . at 1 . to_json
map.insert key val
Json.Object fs
## Parses an RFC-8259 compliant JSON text into a `Json` structure.
Arguments:
- json_text: The RFC-8259-compliant JSON text.
> Example
Convert some text representing a JSON object into JSON.
import Standard.Base.Data.Json.Json
example_parse = Json.parse '{ "a": 1 }'
parse : Text -> Json ! Json_Parse_Error
parse json_text =
Panic.catch_java Any (Internal.parse_helper json_text) java_exception->
Error.throw (Json_Parse_Error.Error java_exception.getMessage)
## A representation of a JSON object.
@ -82,11 +77,11 @@ type Json
## A representation of a JSON null.
Null
## Marshalls this JSON into an arbitrary value described by
## Marshals this JSON into an arbitrary value described by
`type_descriptor`.
Arguments:
- `type_dscriptor`: The type descriptor is a fully-applied type,
- type_descriptor: The type descriptor is a fully-applied type,
describing all required sub-types. It can either be an Atom or one of
the primitive types (`Number`, `Text`, `Boolean`, `Vector`).
@ -95,7 +90,6 @@ type Json
type. It will return a vector of `Book` objects containing data from
`json_string`.
import Standard.Base.Data.Json
import Standard.Examples
type Book title author
@ -121,7 +115,6 @@ type Json
> Example
Convert some JSON to text.
import Standard.Base.Data.Json
import Standard.Examples
example_to_text = Examples.json.to_text
@ -133,17 +126,17 @@ type Json
> Example
Unwrap the JSON number 3 to the primitive number 3.
import Standard.Base.Data.Json
import Standard.Base.Data.Json.Json
example_unwrap = Json.Number 3 . unwrap
unwrap : Any
unwrap self = case self of
Array its -> its.map .unwrap
Boolean b -> b
Number n -> n
String t -> t
Null -> Nothing
Object f -> f.map .unwrap
Json.Array its -> its.map .unwrap
Json.Boolean b -> b
Json.Number n -> n
Json.String t -> t
Json.Null -> Nothing
Json.Object f -> f.map .unwrap
## Gets the value associated with the given key in this object.
@ -155,28 +148,23 @@ type Json
> Example
Get the "title" field from this JSON representing a book.
import Standard.Base.Data.Json
import Standard.Examples
example_get = Examples.json_object.get "title"
get : Text -> Json ! No_Such_Field_Error
get : Text -> Json ! No_Such_Field
get self field = case self of
Object _ -> self.fields.get field . map_error case _ of
Map.No_Value_For_Key_Error_Data _ -> No_Such_Field_Error_Data field
Json.Object _ -> self.fields.get field . map_error case _ of
No_Value_For_Key.Error _ -> No_Such_Field.Error field
x -> x
_ -> Error.throw (Illegal_Argument_Error_Data "Json.get: self must be an Object")
# TODO Dubious constructor export
from project.Data.Json.Parse_Error import all
from project.Data.Json.Parse_Error export all
## UNSTABLE
A failure indicating malformed text input into the JSON parser.
Check the `message` field for detailed information on the specific failure.
type Parse_Error
Parse_Error_Data message
type Json_Parse_Error
Error message
## PRIVATE
@ -185,15 +173,11 @@ type Parse_Error
to_display_text self =
"Parse error in parsing JSON: " + self.message.to_text + "."
# TODO Dubious constructor export
from project.Data.Json.No_Such_Field_Error import all
from project.Data.Json.No_Such_Field_Error export all
## UNSTABLE
An error indicating that there is no such field in the JSON object.
type No_Such_Field_Error
No_Such_Field_Error_Data field_name
type No_Such_Field
Error field_name
## PRIVATE
@ -202,10 +186,6 @@ type No_Such_Field_Error
to_display_text self =
"The field " + self.field_name.to_text + " is not present in this object."
# TODO Dubious constructor export
from project.Data.Json.Marshalling_Error import all
from project.Data.Json.Marshalling_Error export all
## UNSTABLE
A failure indicating the inability to marshall a `Json` object into the
@ -222,7 +202,7 @@ type Marshalling_Error
- format: The type format that did not match.
This can occur e.g. when trying to reinterpret a number as a `Text`, etc.
Type_Mismatch_Error json format
Type_Mismatch json format
## UNSTABLE
@ -236,18 +216,18 @@ type Marshalling_Error
This can occure when trying to reinterpret a JSON object into an atom,
when the JSON does not contain all the fields required by the atom.
Missing_Field_Error json field format
Missing_Field json field format
## UNSTABLE
Convert the marshalling error into a human-readable format.
to_display_text : Text
to_display_text self = case self of
Type_Mismatch_Error json format ->
Marshalling_Error.Type_Mismatch json format ->
json_text = Meta.get_simple_type_name json
format_text = Meta.get_simple_type_name format
"Type mismatch error: the json with type `" + json_text + "` did not match the format `" + format_text + "`."
Missing_Field_Error _ field _ ->
Marshalling_Error.Missing_Field _ field _ ->
"Missing field in Json: the field `" + field.to_text "` was missing in the json."
## ALIAS To JSON
@ -261,6 +241,7 @@ type Marshalling_Error
> Example
Convert a vector to JSON.
[1, 2, 3, 4].to_json
Any.to_json : Json
Any.to_json self =
m = Meta.meta self
case m of
@ -270,15 +251,28 @@ Any.to_json self =
fnames = cons.fields
json_fs = 0.up_to fnames.length . fold Map.empty m-> i->
m.insert (fnames.at i) (fs.at i . to_json)
with_tp = json_fs . insert "type" (String cons.name)
Object with_tp
with_tp = json_fs . insert "type" (Json.String cons.name)
Json.Object with_tp
Meta.Constructor_Data _ ->
Object (Map.empty . insert "type" (String m.name))
Json.Object (Map.empty . insert "type" (Json.String m.name))
## The following two cases cannot be handled generically and should
instead define their own `to_json` implementations.
Meta.Polyglot_Data _ -> Null
Meta.Primitive_Data _ -> Null
Meta.Polyglot_Data _ -> Json.Null
Meta.Primitive_Data _ -> Json.Null
## Text to JSON conversion.
> Example
Convert the text "Hello World!" to JSON.
"Hello World!".to_json
> Example
Convert the text "cześć" to JSON.
"cześć".to_json
Text.to_json : Json
Text.to_json self = Json.String self
## Method used by object builders to convert a value into a valid JSON key.
@ -293,14 +287,13 @@ Text.to_json_key self = self
> Example
Convert `True` to JSON.
True.to_json
Base.Boolean.to_json : Boolean
Base.Boolean.to_json self = Boolean self
Boolean.to_json : Json
Boolean.to_json self = Json.Boolean self
## Convert `Nothing` to JSON.
> Example
Convert `Nothing` to JSON.
Nothing.to_json
Nothing.to_json : Null
Nothing.to_json self = Null
Nothing.to_json : Json
Nothing.to_json self = Json.Null

View File

@ -1,23 +1,25 @@
from Standard.Base import all hiding Number, Boolean, Array
import Standard.Base
from Standard.Base import all
from project.Data.Json import Marshalling_Error
import Standard.Base.Data.Numbers as Base_Number
import Standard.Base.Runtime.Ref
from Standard.Base.Data.Json import all
import project.Runtime.Ref
polyglot java import org.enso.base.json.Parser
polyglot java import org.enso.base.json.Printer
# TODO Dubious constructor export
from project.Data.Json.Internal.Consumer import all
from project.Data.Json.Internal.Consumer export all
## PRIVATE
A JSON parser event consumer, passed to the Java parser backend.
Conforms to the `org.enso.base.json.Parser.JsonConsumer` Java interface.
type Consumer
## PRIVATE
Creates a new top-level consumer.
new : Consumer
new =
child = Ref.new List.Nil
val = Ref.new Nothing
Consumer.Value child val
## PRIVATE
@ -28,7 +30,7 @@ type Consumer
- value: The value being consumed.
Conforms to the `org.enso.base.json.Parser.JsonConsumer` Java interface.
Consumer_Data child_consumer value
Value child_consumer value
## PRIVATE
@ -38,7 +40,7 @@ type Consumer
- v: The value to act upon.
on_value : Any -> Nothing
on_value self v = case self.child_consumer . get of
Nil -> self.value . put v
List.Nil -> self.value . put v
cons -> cons.on_value v
## PRIVATE
@ -50,7 +52,7 @@ type Consumer
child = self.child_consumer.get
val = child.seal
case child.parent of
Nil ->
List.Nil ->
self.value . put val
p ->
self.child_consumer . put p
@ -62,7 +64,7 @@ type Consumer
on_start_object : Nothing
on_start_object self =
parent = self.child_consumer . get
self.child_consumer . put (mk_object_consumer parent)
self.child_consumer . put (Object_Consumer.new parent)
## PRIVATE
@ -85,7 +87,7 @@ type Consumer
on_start_array : Nothing
on_start_array self =
parent = self.child_consumer . get
self.child_consumer . put (mk_array_consumer parent)
self.child_consumer . put (Array_Consumer.new parent)
## PRIVATE
@ -100,7 +102,7 @@ type Consumer
Arguments:
- n: The long value to process.
on_long : Integer -> Nothing
on_long self n = self.on_value (Number n)
on_long self n = self.on_value (Json.Number n)
## PRIVATE
@ -109,7 +111,7 @@ type Consumer
Arguments:
- n: The double value to process.
on_double : Decimal -> Nothing
on_double self n = self.on_value (Number n)
on_double self n = self.on_value (Json.Number n)
## PRIVATE
@ -118,34 +120,40 @@ type Consumer
Arguments:
- s: The string value to process.
on_string : Text -> Nothing
on_string self s = self.on_value (String s)
on_string self s = self.on_value (Json.String s)
## PRIVATE
Consumes the `true` event.
on_true : Nothing
on_true self = self.on_value (Boolean True)
on_true self = self.on_value (Json.Boolean True)
## PRIVATE
Consumes the `false` event.
on_false : Nothing
on_false self = self.on_value (Boolean False)
on_false self = self.on_value (Json.Boolean False)
## PRIVATE
Consumes the `null` event.
on_null : Nothing
on_null self = self.on_value Null
# TODO Dubious constructor export
from project.Data.Json.Internal.Array_Consumer import all
from project.Data.Json.Internal.Array_Consumer export all
on_null self = self.on_value Json.Null
## PRIVATE
A child consumer, used to process events inside arrays.
type Array_Consumer
## PRIVATE
Creates a new array consumer with the given parent.
Arguments:
- parent: The parent of the new consumer.
new : Any -> Array_Consumer
new parent =
Array_Consumer.Value Vector.new_builder parent
## PRIVATE
A child consumer, used to process events inside arrays.
@ -153,7 +161,7 @@ type Array_Consumer
Arguments:
- builder: The builder for array values.
- parent: The parent consumer.
Array_Consumer_Data builder parent
Value builder parent
## PRIVATE
@ -167,19 +175,27 @@ type Array_Consumer
## PRIVATE
Returns the final value built by this consumer.
seal : Array
seal : Json
seal self =
vec = self.builder.to_vector
Array vec
# TODO Dubious constructor export
from project.Data.Json.Internal.Object_Consumer import all
from project.Data.Json.Internal.Object_Consumer export all
Json.Array vec
## PRIVATE
A child consumer, used to process events inside objects.
type Object_Consumer
## PRIVATE
Creates a new object consumer with the given parent.
Arguments:
- parent: The parent of the new consumer.
new : Any -> Object_Consumer
new parent =
k = Ref.new ""
m = Ref.new Map.empty
Object_Consumer.Value k m parent
## PRIVATE
A child consumer, used to process events inside objects.
@ -188,7 +204,7 @@ type Object_Consumer
- last_key: The last object key that has been seen.
- map: The map representing the object.
- parent: The parent consumer.
Object_Consumer_Data last_key map parent
Value last_key map parent
## PRIVATE
@ -215,42 +231,10 @@ type Object_Consumer
## PRIVATE
Returns the final value built by this consumer.
seal : Object
seal : Json
seal self =
m = self.map . get
Object m
## PRIVATE
Creates a new object consumer with the given parent.
Arguments:
- parent: The parent of the new consumer.
mk_object_consumer : Any -> Object_Consumer
mk_object_consumer parent =
k = Ref.new ""
m = Ref.new Map.empty
Object_Consumer_Data k m parent
## PRIVATE
Creates a new array consumer with the given parent.
Arguments:
- parent: The parent of the new consumer.
mk_array_consumer : Any -> Array_Consumer
mk_array_consumer parent =
bldr = Vector.new_builder
Array_Consumer_Data bldr parent
## PRIVATE
Creates a new top-level consumer.
mk_consumer : Consumer
mk_consumer =
child = Ref.new Nil
val = Ref.new Nothing
Consumer_Data child val
Json.Object m
## PRIVATE
@ -261,7 +245,7 @@ mk_consumer =
- json: The json value being converted to text.
render_helper : Text -> Json -> Text
render_helper builder json = case json of
Object fields ->
Json.Object fields ->
r = Ref.new ""
render_key_value acc key value =
separator = r . get
@ -270,7 +254,7 @@ render_helper builder json = case json of
acc + separator + (Printer.json_escape key) + ":" + val
arr = fields.fold_with_key "" render_key_value
builder + "{" + arr + "}"
Array items ->
Json.Array items ->
r = Ref.new ""
render_array_element acc element =
separator = r.get
@ -279,14 +263,14 @@ render_helper builder json = case json of
acc + separator + val
arr = items.fold "" render_array_element
builder + "[" + arr + "]"
String value ->
Json.String value ->
builder + (Printer.json_escape value)
Number value ->
Json.Number value ->
builder + value.to_text
Boolean value ->
Json.Boolean value ->
val = if value then "true" else "false"
builder + val
Null ->
Json.Null ->
builder + "null"
## PRIVATE
@ -300,33 +284,33 @@ render_helper builder json = case json of
See `Json.into` for semantics documentation.
into_helper : Any -> Json -> Any
into_helper fmt json = case fmt of
_ : Base.Vector -> case json of
Array items -> items.map (into_helper (fmt.at 0))
_ -> Panic.throw (Type_Mismatch_Error json fmt)
_ : Base.Boolean -> case json of
Boolean v -> v
_ -> Panic.throw (Type_Mismatch_Error json fmt)
_ : Base_Number.Number -> case json of
Number v -> v
_ -> Panic.throw (Type_Mismatch_Error json fmt)
_ : Base.Text -> case json of
String v -> v
_ -> Panic.throw (Type_Mismatch_Error json fmt)
_ : Vector -> case json of
Json.Array items -> items.map (into_helper (fmt.at 0))
_ -> Panic.throw (Marshalling_Error.Type_Mismatch json fmt)
_ : Boolean -> case json of
Json.Boolean v -> v
_ -> Panic.throw (Marshalling_Error.Type_Mismatch json fmt)
_ : Number -> case json of
Json.Number v -> v
_ -> Panic.throw (Marshalling_Error.Type_Mismatch json fmt)
_ : Text -> case json of
Json.String v -> v
_ -> Panic.throw (Marshalling_Error.Type_Mismatch json fmt)
_ ->
m = Meta.meta fmt
case m of
Meta.Atom_Data _ -> case json of
Object json_fields ->
Json.Object json_fields ->
cons = Meta.Constructor_Data m.constructor
fnames = cons.fields
ffmts = m.fields
field_values = fnames.zip ffmts n-> inner_fmt->
fjson = json_fields . get n . catch Any _->
Panic.throw (Missing_Field_Error json fmt n)
into_helper inner_fmt fjson
field_names = cons.fields
field_formats = m.fields
field_values = field_names.zip field_formats n-> inner_format->
field_json = json_fields . get n . catch Any _->
Panic.throw (Marshalling_Error.Missing_Field json fmt n)
into_helper inner_format field_json
cons.new field_values
_ -> Panic.throw (Type_Mismatch_Error json fmt)
_ -> Panic.throw (Type_Mismatch_Error json fmt)
_ -> Panic.throw (Marshalling_Error.Type_Mismatch json fmt)
_ -> Panic.throw (Marshalling_Error.Type_Mismatch json fmt)
## PRIVATE
@ -336,6 +320,6 @@ into_helper fmt json = case fmt of
- json_text: The textual representation of the JSON.
parse_helper : Text -> Json
parse_helper json_text =
consumer = mk_consumer
consumer = Consumer.new
Parser.parse json_text consumer
consumer.value . get

View File

@ -1,15 +1,16 @@
from Standard.Base.Data.Numbers import all
from Standard.Base.Error.Common import Error
from Standard.Base.Data.Boolean import True, False
import Standard.Base.Data.Filter_Condition.Filter_Condition
import Standard.Base.Data.Vector.Vector
import Standard.Base.Function.Function
import Standard.Base.Nothing
import Standard.Base.Runtime.Unsafe
import project.Data.Any.Any
import project.Data.Filter_Condition.Filter_Condition
import project.Data.Numbers.Number
import project.Data.Numbers.Integer
import project.Data.Vector.Vector
import project.Function.Function
import project.Nothing.Nothing
import project.Runtime.Unsafe
# TODO Dubious constructor export
from project.Data.List.List import all
from project.Data.List.List export all
from project.Data.Boolean import Boolean, True, False
from project.Error.Common import Error
from project.Data.List.List import Nil, Cons
## The basic cons-list type.
@ -185,10 +186,10 @@ type List
_ : Filter_Condition -> self.filter filter.to_predicate
predicate : Function ->
go_filter list = case list of
Nil -> Nil
Cons h t ->
rest = go_filter t
if predicate h then Cons h rest else rest
Nil -> Nil
go_filter self
## Applies a function to each element of the list, returning the list of
@ -261,8 +262,8 @@ type List
example_drop_start = Examples.list.drop_start 1
drop_start : Integer -> List
drop_start self count = if count <= 0 then self else case self of
Cons _ b -> b.drop_start count-1
Nil -> Nil
Cons _ b -> b.drop_start count-1
## Creates a new list consisting of the first `count` elements at the start
of `self`.
@ -278,8 +279,8 @@ type List
example_take_start = Examples.list.take_start 2
take_start : Integer -> List
take_start self count = if count <= 0 then Nil else case self of
Cons a b -> Cons a (b.take_start count-1)
Nil -> Nil
Cons a b -> Cons a (b.take_start count-1)
## Get the first element from the list.
@ -291,8 +292,8 @@ type List
example_head = Examples.list.x
head : Any ! Empty_Error
head self = case self of
Cons a _ -> a
Nil -> Error.throw Empty_Error
Cons a _ -> a
## Get all elements from the list except the first.
@ -304,8 +305,8 @@ type List
example_tail = Examples.list.tail
tail : List ! Empty_Error
tail self = case self of
Cons _ b -> b
Nil -> Error.throw Empty_Error
Cons _ b -> b
## Get all elements from the list except the last.
@ -317,12 +318,12 @@ type List
example_init = Examples.list.init
init : List ! Empty_Error
init self =
init' x y = case y of
init_fn x y = case y of
Nil -> Nil
Cons a b -> Cons x (init' a b)
Cons a b -> Cons x (init_fn a b)
case self of
Cons a b -> init' a b
Nil -> Error.throw Empty_Error
Cons a b -> init_fn a b
## Get the last element of the list.
@ -390,8 +391,8 @@ type Empty_Error
to the user-facing API.
map_helper : List -> Any -> (Any -> Any) -> Nothing
map_helper list cons f = case list of
Nil -> Unsafe.set_atom_field cons 1 Nil
Cons h t ->
res = Cons (f h) Nil
Unsafe.set_atom_field cons 1 res
@Tail_Call map_helper t res f
Nil -> Unsafe.set_atom_field cons 1 Nil

View File

@ -6,294 +6,6 @@ polyglot java import java.util.Locale as JavaLocale
# These are chosen as the union of the top 10 countries by population, and the
# top ten countries by total (nominal, not per-capita) GDP.
## The default locale.
The default locale is a locale that does not specify any language, country,
or variant and is used as the language/country-neutral setting for locale
sensitive operations.
default : Locale
default = from_java JavaLocale.ROOT
## A locale representing Bangladesh.
> Example
Get the Bangladeshi locale.
import Standard.Base.Data.Locale
example_locale = Locale.bangladesh
bangladesh : Locale
bangladesh = from_language_tag "bn-BD"
## A locale representing Brazil.
> Example
Get the Brazilian locale.
import Standard.Base.Data.Locale
example_locale = Locale.brazil
brazil : Locale
brazil = from_language_tag "pt-BR"
## A locale representing Canada with language English.
> Example
Get the Canadian english locale.
import Standard.Base.Data.Locale
example_locale = Locale.canada_english
canada_english : Locale
canada_english = from_language_tag "en-CA"
## A locale representing Canada with language French.
> Example
Get the Canadian french locale.
import Standard.Base.Data.Locale
example_locale = Locale.canada_french
canada_french : Locale
canada_french = from_language_tag "fr-CA"
## A locale representing the PRC.
> Example
Get the PRC locale.
import Standard.Base.Data.Locale
example_locale = Locale.china
china : Locale
china = from_language_tag "zh-CN"
## A locale representing France.
> Example
Get the French locale.
import Standard.Base.Data.Locale
example_locale = Locale.france
france : Locale
france = from_language_tag "fr-FR"
## A locale representing Germany.
> Example
Get the German locale.
import Standard.Base.Data.Locale
example_locale = Locale.germany
germany : Locale
germany = from_language_tag "de-DE"
## A locale representing India with language Hindi.
> Example
Get the Indian hindi locale.
import Standard.Base.Data.Locale
example_locale = Locale.india_hindi
india_hindi : Locale
india_hindi = from_language_tag "hi-IN"
## A locale representing India with language English.
> Example
Get the Indian english locale.
import Standard.Base.Data.Locale
example_locale = Locale.india_english
india_english : Locale
india_english = from_language_tag "en-IN"
## A locale representing Indonesia.
> Example
Get the Indonesian locale.
import Standard.Base.Data.Locale
example_locale = Locale.indonesia
indonesia : Locale
indonesia = from_language_tag "id-ID"
## A locale representing Italy.
> Example
Get the Italian locale.
import Standard.Base.Data.Locale
example_locale = Locale.italy
italy : Locale
italy = from_language_tag "it-IT"
## A locale representing Japan.
> Example
Get the Japanese locale.
import Standard.Base.Data.Locale
example_locale = Locale.japan
japan : Locale
japan = from_language_tag "jp-JP"
## A locale representing Mexico.
> Example
Get the Mexican locale.
import Standard.Base.Data.Locale
example_locale = Locale.mexico
mexico : Locale
mexico = from_language_tag "es-MX"
## A locale representing Nigeria.
> Example
Get the Nigerian locale.
import Standard.Base.Data.Locale
example_locale = Locale.nigeria
nigeria : Locale
nigeria = from_language_tag "en-NG"
## A locale representing paksitan with language Urdu.
> Example
Get the Pakistani urdu locale.
import Standard.Base.Data.Locale
example_locale = Locale.pakistan_urdu
pakistan_urdu : Locale
pakistan_urdu = from_language_tag "ur-PK"
## A locale representing paksitan with language English.
> Example
Get the Pakistani english locale.
import Standard.Base.Data.Locale
example_locale = Locale.pakistan_english
pakistan_english : Locale
pakistan_english = from_language_tag "en-PK"
## A locale representing Russia.
> Example
Get the Russian locale.
import Standard.Base.Data.Locale
example_locale = Locale.russia
russia : Locale
russia = from_language_tag "ru-RU"
## A locale representing South Korea.
> Example
Get the South Korean locale.
import Standard.Base.Data.Locale
example_locale = Locale.south_korea
south_korea : Locale
south_korea = from_language_tag "ko-KR"
## A locale representing the UK.
> Example
Get the british locale.
import Standard.Base.Data.Locale
example_locale = Locale.uk
uk : Locale
uk = from_language_tag "en-GB"
## A locale representing the United States.
> Example
Get the US locale.
import Standard.Base.Data.Locale
example_locale = Locale.us
us : Locale
us = from_language_tag "en-US"
## Construct a new locale.
Arguments:
- language: The language tag for the locale.
- country: The country tag for the locale.
- variant: The variant for the locale.
> Example
A locale representing en-GB.UTF-8.
import Standard.Base.Data.Locale
example_new = Locale.new "en" "GB" "UTF-8"
new : Text -> Text | Nothing -> Text | Nothing -> Locale
new language country=Nothing variant=Nothing =
country_text = country.if_nothing ""
variant_text = variant.if_nothing ""
java_locale = JavaLocale.new language country_text variant_text
from_java java_locale
## Returns the locale specified by the provided IETF BCP47 language tag string.
? Language Tag Syntax
If the specified language tag contains any ill-formed subtags, the first
such subtag and all following subtags are ignored.
The following conversions are performed:
- The language code "und" is mapped to language "".
- The language codes "he", "yi", and "id" are mapped to "iw", "ji", and
"in" respectively.
- The portion of a private use subtag prefixed by "lvariant", if any, is
removed and appended to the variant field in the result locale (without
case normalization).
- When the languageTag argument contains an extlang subtag, the first such
subtag is used as the language, and the primary language subtag and other
extlang subtags are ignored.
- Case is normalized except for variant tags, which are left unchanged.
Language is normalized to lower case, script to title case, country to
upper case, and extensions to lower case.
- If, after processing, the locale would exactly match either ja_JP_JP or
th_TH_TH with no extensions, the appropriate extensions are added.
This implements the 'Language-Tag' production of BCP47, and so supports
grandfathered (regular and irregular) as well as private use language tags.
> Example
Creating the locale en_US.
import Standard.Base.Data.Locale
example_from_tag = Locale.from_language_tag "en_US"
from_language_tag : Text -> Locale
from_language_tag tag =
java_locale = JavaLocale.forLanguageTag tag
from_java java_locale
# TODO Dubious constructor export
from project.Data.Locale.Locale import all
from project.Data.Locale.Locale export all
## A type representing a locale.
A locale consists of three parts:
@ -301,20 +13,323 @@ from project.Data.Locale.Locale export all
- A country code, which is optional.
- A variant, which is optional.
type Locale
## Construct a new locale.
Arguments:
- language: The language tag for the locale.
- country: The country tag for the locale.
- variant: The variant for the locale.
> Example
A locale representing en-GB.UTF-8.
import Standard.Base.Data.Locale.Locale
example_new = Locale.new "en" "GB" "UTF-8"
new : Text -> Text | Nothing -> Text | Nothing -> Locale
new language country=Nothing variant=Nothing =
country_text = country.if_nothing ""
variant_text = variant.if_nothing ""
java_locale = JavaLocale.new language country_text variant_text
Locale.Value java_locale
## ADVANCED
Convert a java locale to an Enso locale.
Arguments:
- java: The java locale value.
from_java : JavaLocale -> Locale
from_java java = Locale.Value java
## Returns the locale specified by the provided IETF BCP47 language tag string.
? Language Tag Syntax
If the specified language tag contains any ill-formed subtags, the first
such subtag and all following subtags are ignored.
The following conversions are performed:
- The language code "und" is mapped to language "".
- The language codes "he", "yi", and "id" are mapped to "iw", "ji", and
"in" respectively.
- The portion of a private use subtag prefixed by "lvariant", if any, is
removed and appended to the variant field in the result locale (without
case normalization).
- When the languageTag argument contains an extlang subtag, the first such
subtag is used as the language, and the primary language subtag and other
extlang subtags are ignored.
- Case is normalized except for variant tags, which are left unchanged.
Language is normalized to lower case, script to title case, country to
upper case, and extensions to lower case.
- If, after processing, the locale would exactly match either ja_JP_JP or
th_TH_TH with no extensions, the appropriate extensions are added.
This implements the 'Language-Tag' production of BCP47, and so supports
grandfathered (regular and irregular) as well as private use language tags.
> Example
Creating the locale en_US.
import Standard.Base.Data.Locale.Locale
example_from_tag = Locale.from_language_tag "en_US"
from_language_tag : Text -> Locale
from_language_tag tag =
java_locale = JavaLocale.forLanguageTag tag
Locale.Value java_locale
## The default locale.
The default locale is a locale that does not specify any language, country,
or variant and is used as the language/country-neutral setting for locale
sensitive operations.
default : Locale
default = Locale.Value JavaLocale.ROOT
## A locale representing Bangladesh.
> Example
Get the Bangladeshi locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.bangladesh
bangladesh : Locale
bangladesh = Locale.from_language_tag "bn-BD"
## A locale representing Brazil.
> Example
Get the Brazilian locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.brazil
brazil : Locale
brazil = Locale.from_language_tag "pt-BR"
## A locale representing Canada with language English.
> Example
Get the Canadian english locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.canada_english
canada_english : Locale
canada_english = Locale.from_language_tag "en-CA"
## A locale representing Canada with language French.
> Example
Get the Canadian french locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.canada_french
canada_french : Locale
canada_french = Locale.from_language_tag "fr-CA"
## A locale representing the PRC.
> Example
Get the PRC locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.china
china : Locale
china = Locale.from_language_tag "zh-CN"
## A locale representing France.
> Example
Get the French locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.france
france : Locale
france = Locale.from_language_tag "fr-FR"
## A locale representing Germany.
> Example
Get the German locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.germany
germany : Locale
germany = Locale.from_language_tag "de-DE"
## A locale representing India with language Hindi.
> Example
Get the Indian hindi locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.india_hindi
india_hindi : Locale
india_hindi = Locale.from_language_tag "hi-IN"
## A locale representing India with language English.
> Example
Get the Indian english locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.india_english
india_english : Locale
india_english = Locale.from_language_tag "en-IN"
## A locale representing Indonesia.
> Example
Get the Indonesian locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.indonesia
indonesia : Locale
indonesia = Locale.from_language_tag "id-ID"
## A locale representing Italy.
> Example
Get the Italian locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.italy
italy : Locale
italy = Locale.from_language_tag "it-IT"
## A locale representing Japan.
> Example
Get the Japanese locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.japan
japan : Locale
japan = Locale.from_language_tag "jp-JP"
## A locale representing Mexico.
> Example
Get the Mexican locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.mexico
mexico : Locale
mexico = Locale.from_language_tag "es-MX"
## A locale representing Nigeria.
> Example
Get the Nigerian locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.nigeria
nigeria : Locale
nigeria = Locale.from_language_tag "en-NG"
## A locale representing paksitan with language Urdu.
> Example
Get the Pakistani urdu locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.pakistan_urdu
pakistan_urdu : Locale
pakistan_urdu = Locale.from_language_tag "ur-PK"
## A locale representing paksitan with language English.
> Example
Get the Pakistani english locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.pakistan_english
pakistan_english : Locale
pakistan_english = Locale.from_language_tag "en-PK"
## A locale representing Poland.
> Example
Get the Poland locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.poland
poland : Locale
poland = Locale.from_language_tag "pl-PL"
## A locale representing Russia.
> Example
Get the Russian locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.russia
russia : Locale
russia = Locale.from_language_tag "ru-RU"
## A locale representing South Korea.
> Example
Get the South Korean locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.south_korea
south_korea : Locale
south_korea = Locale.from_language_tag "ko-KR"
## A locale representing the UK.
> Example
Get the british locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.uk
uk : Locale
uk = Locale.from_language_tag "en-GB"
## A locale representing the United States.
> Example
Get the US locale.
import Standard.Base.Data.Locale.Locale
example_locale = Locale.us
us : Locale
us = Locale.from_language_tag "en-US"
## PRIVATE
A type representing a locale.
Arguments:
- java_locale: The Java locale representation used internally.
Locale_Data java_locale
Value java_locale
## Gets the language from the locale.
> Example
Get the language tag from the default locale.
import Standard.Base.Data.Locale
import Standard.Base.Data.Locale.Locale
example_language = Locale.default.language
language : Text | Nothing
@ -327,7 +342,7 @@ type Locale
> Example
Get the country tag from the default locale.
import Standard.Base.Data.Locale
import Standard.Base.Data.Locale.Locale
example_country = Locale.default.country
country : Text | Nothing
@ -340,7 +355,7 @@ type Locale
> Example
Get the variant tag from the default locale.
import Standard.Base.Data.Locale
import Standard.Base.Data.Locale.Locale
example_variant = Locale.default.variant
variant : Text | Nothing
@ -354,7 +369,7 @@ type Locale
> Example
Get the display language tag from the default locale.
import Standard.Base.Data.Locale
import Standard.Base.Data.Locale.Locale
example_display_language = Locale.default.display_language
display_language : Text | Nothing
@ -368,7 +383,7 @@ type Locale
> Example
Get the display country tag from the default locale.
import Standard.Base.Data.Locale
import Standard.Base.Data.Locale.Locale
example_display_country = Locale.default.display_country
display_country : Text | Nothing
@ -382,7 +397,7 @@ type Locale
> Example
Get the display variant tag from the default locale.
import Standard.Base.Data.Locale
import Standard.Base.Data.Locale.Locale
example_display_variant = Locale.default.display_variant
display_variant : Text | Nothing
@ -395,7 +410,7 @@ type Locale
> Example
Convert the default locale to text.
import Standard.Base.Data.Locale
import Standard.Base.Data.Locale.Locale
example_to_text = Locale.default.to_text
to_text : Text | Nothing
@ -406,10 +421,10 @@ type Locale
> Example
Convert the default locale to JSON.
import Standard.Base.Data.Locale
import Standard.Base.Data.Locale.Locale
example_to_json = Locale.default.to_json
to_json : Json.Object
to_json : Json
to_json self =
b = Vector.new_builder
b.append ["type", "Locale"]
@ -421,14 +436,5 @@ type Locale
## Compares two locales for equality.
== : Any -> Boolean
== self other = case other of
Locale_Data other_java_locale -> self.java_locale.equals other_java_locale
Locale.Value other_java_locale -> self.java_locale.equals other_java_locale
_ -> False
## PRIVATE
Convert a java locale to an Enso locale.
Arguments:
- java: The java locale value.
from_java : JavaLocale -> Locale
from_java java = Locale_Data java

View File

@ -1,54 +1,58 @@
from Standard.Base import all
import project.Data.Any.Any
import project.Data.Numbers.Integer
import project.Data.Ordering.Ordering
import project.Data.Text.Text
import project.Data.Vector.Vector
import project.Data.Pair.Pair
import project.Nothing.Nothing
import Standard.Base.Data.Map.Internal
from project.Data.Boolean import Boolean, True, False
from project.Error.Common import Error
## Returns an empty map.
> Example
Create an empty map.
import Standard.Base.Data.Map.Internal
example_empty = Map.empty
empty : Map
empty = Tip
## Returns a single-element map with the given key and value present.
Arguments:
- key: The key to update in the map.
- value: The value to store against 'key' in the map.
> Example
Create a single element map storing the key 1 and the value 2.
import Standard.Base.Data.Map.Internal
example_singleton = Map.singleton 1 2
singleton : Any -> Any -> Map
singleton key value = Bin 1 key value Tip Tip
## Builds a map from a vector of key-value pairs.
Arguments:
- vec: A vector of key-value pairs.
> Example
Building a map containing two key-value pairs.
import Standard.Base.Data.Map.Internal
example_from_vector = Map.from_vector [[1, 2], [3, 4]]
from_vector : Vector Any -> Map
from_vector vec = vec.fold empty (m -> el -> m.insert (el.at 0) (el.at 1))
# TODO Dubious constructor export
from project.Data.Map.Map import all
from project.Data.Map.Map export all
import project.Data.Map.Internal
## A key-value store. This type assumes all keys are pairwise comparable,
using the `<`, `>` and `==` operators.
type Map
## Returns an empty map.
> Example
Create an empty map.
import Standard.Base.Data.Map.Map
example_empty = Map.empty
empty : Map
empty = Map.Tip
## Returns a single-element map with the given key and value present.
Arguments:
- key: The key to update in the map.
- value: The value to store against 'key' in the map.
> Example
Create a single element map storing the key 1 and the value 2.
import Standard.Base.Data.Map.Map
example_singleton = Map.singleton 1 2
singleton : Any -> Any -> Map
singleton key value = Map.Bin 1 key value Map.Tip Map.Tip
## Builds a map from a vector of key-value pairs.
Arguments:
- vec: A vector of key-value pairs.
> Example
Building a map containing two key-value pairs.
import Standard.Base.Data.Map.Map
example_from_vector = Map.from_vector [[1, 2], [3, 4]]
from_vector : Vector Any -> Map
from_vector vec = vec.fold Map.empty (m -> el -> m.insert (el.at 0) (el.at 1))
## PRIVATE
A key-value store. This type assumes all keys are pairwise comparable,
@ -72,21 +76,21 @@ type Map
> Example
Check if a map is empty.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_is_empty = Examples.map.is_empty
is_empty : Boolean
is_empty self = case self of
Bin _ _ _ _ _ -> False
Tip -> True
Map.Bin _ _ _ _ _ -> False
Map.Tip -> True
## Checks if the map is not empty.
> Example
Check if a map is not empty.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_not_empty = Examples.map.not_empty
@ -98,14 +102,14 @@ type Map
> Example
Get the size of a map.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_size = Examples.map.size
size : Integer
size self = case self of
Bin s _ _ _ _ -> s
Tip -> 0
Map.Bin s _ _ _ _ -> s
Map.Tip -> 0
## Converts the map into a vector of `[key, value]` pairs.
@ -114,7 +118,7 @@ type Map
> Example
Convert a map to a vector.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_to_vector = Examples.map.to_vector
@ -122,12 +126,12 @@ type Map
to_vector self =
builder = Vector.new_builder
to_vector_with_builder m = case m of
Bin _ k v l r ->
Map.Bin _ k v l r ->
to_vector_with_builder l
builder.append [k, v]
to_vector_with_builder r
Nothing
Tip -> Nothing
Map.Tip -> Nothing
to_vector_with_builder self
result = builder.to_vector
result
@ -137,7 +141,7 @@ type Map
> Example
Convert a map to text.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_to_text = Examples.map.to_text
@ -155,7 +159,7 @@ type Map
> Example
Checking two maps for equality.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_equals =
@ -174,7 +178,7 @@ type Map
> Example
Insert the value "seven" into the map for the key 7.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_insert = Examples.map.insert 7 "seven"
@ -190,13 +194,13 @@ type Map
> Example
Get the value for the key 1 in a map.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_get = Examples.map.get 1
get : Any -> Any ! No_Value_For_Key_Error
get : Any -> Any ! No_Value_For_Key
get self key =
self.get_or_else key (Error.throw (No_Value_For_Key_Error_Data key))
self.get_or_else key (Error.throw (No_Value_For_Key.Error key))
## Gets the value associated with `key` in this map, or returns `other` if
it isn't present.
@ -209,15 +213,15 @@ type Map
Get the value for the key 2 in a map or instead return "zero" if it
isn't present.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_get_or_else = Examples.map.get_or_else 2 "zero"
get_or_else : Any -> Any -> Any
get_or_else self key ~other =
go map = case map of
Tip -> other
Bin _ k v l r -> case Internal.compare_allow_nothing key k of
Map.Tip -> other
Map.Bin _ k v l r -> case Internal.compare_allow_nothing key k of
Ordering.Equal -> v
Ordering.Less -> @Tail_Call go l
Ordering.Greater -> @Tail_Call go r
@ -233,7 +237,7 @@ type Map
> Example
Turn all keys into `Text` and append "_word" to the values in the map.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_transform =
@ -242,7 +246,7 @@ type Map
transform self function =
func_pairs = p -> function (p.at 0) (p.at 1)
vec_transformed = self.to_vector.map func_pairs
from_vector vec_transformed
Map.from_vector vec_transformed
## Maps a function over each value in this map.
@ -253,7 +257,7 @@ type Map
> Example
Append "_word" to all values in the map.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_map = Examples.map.map (+ "_word")
@ -272,7 +276,7 @@ type Map
> Example
Prepend the keys to the values in the map.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_map_with_key =
@ -280,9 +284,9 @@ type Map
map_with_key : (Any -> Any -> Any) -> Map
map_with_key self function =
go map = case map of
Bin s k v l r ->
Bin s k (function k v) (go l) (go r)
Tip -> Tip
Map.Bin s k v l r ->
Map.Bin s k (function k v) (go l) (go r)
Map.Tip -> Map.Tip
go self
## Maps a function over each key in this map.
@ -294,7 +298,7 @@ type Map
> Example
Doubling all keys in the map.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_map_keys = Examples.map.map_keys *2
@ -315,7 +319,7 @@ type Map
> Example
Printing each value in the map.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_each = Examples.map.each IO.println
@ -336,7 +340,7 @@ type Map
> Example
Printing each key and value in the map.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_each_with_key = Examples.map.each_with_key k->v->
@ -345,12 +349,12 @@ type Map
each_with_key : (Any -> Any -> Any) -> Nothing
each_with_key self function =
go map = case map of
Bin _ k v l r ->
Map.Bin _ k v l r ->
go l
function k v
go r
Nothing
Tip -> Nothing
Map.Tip -> Nothing
go self
## Combines the values in the map.
@ -362,18 +366,18 @@ type Map
> Example
Find the length of the longest word in the map.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_fold = Examples.map.fold 0 (l -> r -> Math.max l r.length)
fold : Any -> (Any -> Any -> Any) -> Any
fold self init function =
go map init = case map of
Bin _ _ v l r ->
Map.Bin _ _ v l r ->
y = go l init
z = function y v
go r z
Tip -> init
Map.Tip -> init
go self init
## Combines the key-value pairs in the map.
@ -386,7 +390,7 @@ type Map
> Example
Glue the values in the map together with the keys.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_fold_with_key =
@ -394,11 +398,11 @@ type Map
fold_with_key : Any -> (Any -> Any -> Any -> Any) -> Any
fold_with_key self init function =
go map init = case map of
Bin _ k v l r ->
Map.Bin _ k v l r ->
y = go l init
z = function y k v
go r z
Tip -> init
Map.Tip -> init
go self init
## Get a vector containing the keys in the map.
@ -406,7 +410,7 @@ type Map
> Example
Get the keys from the map `m`.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_keys = Examples.map.keys
@ -414,12 +418,12 @@ type Map
keys self =
builder = Vector.new_builder
to_vector_with_builder m = case m of
Bin _ k _ l r ->
Map.Bin _ k _ l r ->
to_vector_with_builder l
builder.append k
to_vector_with_builder r
Nothing
Tip -> Nothing
Map.Tip -> Nothing
to_vector_with_builder self
builder.to_vector
@ -428,7 +432,7 @@ type Map
> Example
Get the values from the map `m`.
import Standard.Base.Data.Map
import Standard.Base.Data.Map.Map
import Standard.Examples
example_values = Examples.map.values
@ -436,12 +440,12 @@ type Map
values self =
builder = Vector.new_builder
to_vector_with_builder m = case m of
Bin _ _ v l r ->
Map.Bin _ _ v l r ->
to_vector_with_builder l
builder.append v
to_vector_with_builder r
Nothing
Tip -> Nothing
Map.Tip -> Nothing
to_vector_with_builder self
builder.to_vector
@ -450,8 +454,8 @@ type Map
first : Pair
first self =
first p m = case m of
Bin _ k v l _ -> @Tail_Call first (Pair_Data k v) l
Tip -> p
Map.Bin _ k v l _ -> @Tail_Call first (Pair.Pair_Data k v) l
Map.Tip -> p
first Nothing self
## Get a key value pair of the highest key in the map.
@ -459,22 +463,18 @@ type Map
last : Pair
last self =
last p m = case m of
Bin _ k v _ r -> @Tail_Call last (Pair_Data k v) r
Tip -> p
Map.Bin _ k v _ r -> @Tail_Call last (Pair.Pair_Data k v) r
Map.Tip -> p
last Nothing self
# TODO Dubious constructor export
from project.Data.Map.No_Value_For_Key_Error import all
from project.Data.Map.No_Value_For_Key_Error export all
## UNSTABLE
An error for getting a missing value from a map.
Arguments:
- key: The key that was asked for.
type No_Value_For_Key_Error
No_Value_For_Key_Error_Data key
type No_Value_For_Key
Error key
## PRIVATE

View File

@ -1,6 +1,7 @@
from Standard.Base import all
from Standard.Base.Data.Map import all
import project.Data.Any.Any
import project.Data.Ordering.Ordering
import project.Data.Map.Map
import project.Data.Numbers.Integer
## PRIVATE
Compares keys allowing for the possibility that one or both keys are Nothing.
@ -21,7 +22,7 @@ compare_allow_nothing x y = if x == y then Ordering.Equal else
- v: The previous top value of the left subtree.
- l: The left subtree.
- r: The right subtree.
insert_l : Any -> Any -> Any -> Any -> Tree -> Tree -> Tree
insert_l : Any -> Any -> Any -> Any -> Map -> Map -> Map
insert_l key value k v l r =
new_left = insert l key value
balance_left k v new_left r
@ -37,7 +38,7 @@ insert_l key value k v l r =
- v: The previous top value of the right subtree.
- l: The left subtree.
- r: The right subtree.
insert_r : Any -> Any -> Any -> Any -> Tree -> Tree -> Tree
insert_r : Any -> Any -> Any -> Any -> Map -> Map -> Map
insert_r key value k v l r =
new_right = insert r key value
balance_right k v l new_right
@ -56,80 +57,81 @@ insert_r key value k v l r =
Haskell's `Data.Map.Strict` as implemented in the `containers` package.
insert : Map -> Any -> Any -> Map
insert map key value = case map of
Bin s k v l r -> case compare_allow_nothing key k of
Map.Bin s k v l r -> case compare_allow_nothing key k of
Ordering.Less -> @Tail_Call insert_l key value k v l r
Ordering.Greater -> @Tail_Call insert_r key value k v l r
Ordering.Equal -> Bin s key value l r
_ -> Bin 1 key value Tip Tip
Ordering.Equal -> Map.Bin s key value l r
_ -> Map.Bin 1 key value Map.Tip Map.Tip
## PRIVATE
Rebalances the map after the left subtree grows.
Re-balances the map after the left subtree grows.
Arguments:
- k: The old top key of the left subtree.
- x: The old top value of the left subtree.
- l: The left subtree.
- r: The right subtree.
balance_left : Any -> Any -> Tree -> Tree -> Tree
balance_left : Any -> Any -> Map -> Map -> Map
balance_left k x l r = case r of
Bin rs _ _ _ _ -> case l of
Bin ls lk lx ll lr ->
if ls <= delta*rs then Bin 1+ls+rs k x l r else
Map.Bin rs _ _ _ _ -> case l of
Map.Bin ls lk lx ll lr ->
if ls <= delta*rs then Map.Bin 1+ls+rs k x l r else
lls = size ll
case lr of
Bin lrs lrk lrx lrl lrr ->
if lrs < ratio*lls then Bin 1+ls+rs lk lx ll (Bin 1+rs+lrs k x lr r) else
Map.Bin lrs lrk lrx lrl lrr ->
if lrs < ratio*lls then Map.Bin 1+ls+rs lk lx ll (Map.Bin 1+rs+lrs k x lr r) else
lrls = size lrl
lrrs = size lrr
Bin 1+ls+rs lrk lrx (Bin 1+lls+lrls lk lx ll lrl) (Bin 1+rs+lrrs k x lrr r)
_ -> Bin 1+rs k x Tip r
Map.Bin 1+ls+rs lrk lrx (Map.Bin 1+lls+lrls lk lx ll lrl) (Map.Bin 1+rs+lrrs k x lrr r)
_ -> Map.Bin 1+rs k x Map.Tip r
_ -> case l of
Tip -> Bin 1 k x Tip Tip
Bin _ _ _ Tip Tip -> Bin 2 k x l Tip
Bin _ lk lx Tip (Bin _ lrk lrx _ _) -> Bin 3 lrk lrx (Bin 1 lk lx Tip Tip) (Bin 1 k x Tip Tip)
Bin _ lk lx ll Tip -> Bin 3 lk lx ll (Bin 1 k x Tip Tip)
Bin ls lk lx ll lr -> case lr of
Bin lrs lrk lrx lrl lrr ->
Map.Tip -> Map.Bin 1 k x Map.Tip Map.Tip
Map.Bin _ _ _ Map.Tip Map.Tip -> Map.Bin 2 k x l Map.Tip
Map.Bin _ lk lx Map.Tip (Map.Bin _ lrk lrx _ _) -> Map.Bin 3 lrk lrx (Map.Bin 1 lk lx Map.Tip Map.Tip) (Map.Bin 1 k x Map.Tip Map.Tip)
Map.Bin _ lk lx ll Map.Tip -> Map.Bin 3 lk lx ll (Map.Bin 1 k x Map.Tip Map.Tip)
Map.Bin ls lk lx ll lr -> case lr of
Map.Bin lrs lrk lrx lrl lrr ->
lls = size ll
if lrs < ratio*lls then Bin 1+ls lk lx ll (Bin 1+lrs k x lr Tip) else
if lrs < ratio*lls then Map.Bin 1+ls lk lx ll (Map.Bin 1+lrs k x lr Map.Tip) else
lrls = size lrl
lrrs = size lrr
Bin 1+ls lrk lrx (Bin 1+lls+lrls lk lx ll lrl) (Bin 1+lrrs k x lrr Tip)
Map.Bin 1+ls lrk lrx (Map.Bin 1+lls+lrls lk lx ll lrl) (Map.Bin 1+lrrs k x lrr Map.Tip)
## PRIVATE
Rebalances the map after the right subtree grows.
Re-balances the map after the right subtree grows.
Arguments:
- k: The old top key of the right subtree.
- x: The old top value of the right subtree.
- l: The left subtree.
- r: The right subtree.
balance_right : Any -> Any -> Map -> Map -> Map
balance_right k x l r = case l of
Bin ls _ _ _ _ -> case r of
Bin rs rk rx rl rr ->
if rs <= delta*ls then Bin 1+ls+rs k x l r else
Map.Bin ls _ _ _ _ -> case r of
Map.Bin rs rk rx rl rr ->
if rs <= delta*ls then Map.Bin 1+ls+rs k x l r else
case rl of
Bin rls rlk rlx rll rlr ->
Map.Bin rls rlk rlx rll rlr ->
rrs = size rr
if rls < ratio*rrs then Bin 1+ls+rs rk rx (Bin 1+ls+rls k x l rl) rr else
if rls < ratio*rrs then Map.Bin 1+ls+rs rk rx (Map.Bin 1+ls+rls k x l rl) rr else
rlls = size rll
rlrs = size rlr
Bin 1+ls+rs rlk rlx (Bin 1+ls+rlls k x l rll) (Bin 1+rrs+rlrs rk rx rlr rr)
_ -> Bin 1+ls k x l Tip
Map.Bin 1+ls+rs rlk rlx (Map.Bin 1+ls+rlls k x l rll) (Map.Bin 1+rrs+rlrs rk rx rlr rr)
_ -> Map.Bin 1+ls k x l Map.Tip
_ -> case r of
Tip -> Bin 1 k x Tip Tip
Bin _ _ _ Tip Tip -> Bin 2 k x Tip r
Bin _ rk rx Tip rr -> Bin 3 rk rx (Bin 1 k x Tip Tip) rr
Bin _ rk rx (Bin _ rlk rlx _ _) Tip -> Bin 3 rlk rlx (Bin 1 k x Tip Tip) (Bin 1 rk rx Tip Tip)
Bin rs rk rx rl rr -> case rl of
Bin rls rlk rlx rll rlr -> case rr of
Bin rrs _ _ _ _ ->
if rls < ratio*rrs then Bin 1+rs rk rx (Bin 1+rls k x Tip rl) rr else
Map.Tip -> Map.Bin 1 k x Map.Tip Map.Tip
Map.Bin _ _ _ Map.Tip Map.Tip -> Map.Bin 2 k x Map.Tip r
Map.Bin _ rk rx Map.Tip rr -> Map.Bin 3 rk rx (Map.Bin 1 k x Map.Tip Map.Tip) rr
Map.Bin _ rk rx (Map.Bin _ rlk rlx _ _) Map.Tip -> Map.Bin 3 rlk rlx (Map.Bin 1 k x Map.Tip Map.Tip) (Map.Bin 1 rk rx Map.Tip Map.Tip)
Map.Bin rs rk rx rl rr -> case rl of
Map.Bin rls rlk rlx rll rlr -> case rr of
Map.Bin rrs _ _ _ _ ->
if rls < ratio*rrs then Map.Bin 1+rs rk rx (Map.Bin 1+rls k x Map.Tip rl) rr else
srll = size rll
srlr = size rlr
Bin 1+rs rlk rlx (Bin 1+srll k x Tip rll) (Bin 1+rrs+srlr rk rx rlr rr)
Map.Bin 1+rs rlk rlx (Map.Bin 1+srll k x Map.Tip rll) (Map.Bin 1+rrs+srlr rk rx rlr rr)
## PRIVATE
@ -158,6 +160,6 @@ delta = 3
- m: The map to get the size of.
size : Map -> Integer
size m = case m of
Bin s _ _ _ _ -> s
Map.Bin s _ _ _ _ -> s
_ -> 0

View File

@ -1,6 +1,62 @@
from Standard.Base import all
import project.Data.Any.Any
import project.Data.Numbers.Number
import project.Data.Interval.Interval
import project.Data.Interval.Bound
from Standard.Base.Data.Noise.Generator import all
from project.Error.Common import unimplemented
polyglot java import java.lang.Long
polyglot java import java.util.Random
## PRIVATE
The interface for the noise generator abstraction.
To be a valid generator, it must provide the `step` method as described
below.
type Generator
## PRIVATE
Step the generator to produce the next value..
Arguments:
- The input number, which is intended for use as a seed.
- A range for output values, which should range over the chosen output
type.
The return type may be chosen freely by the generator implementation, as
it usually depends on the generator and its intended use.
step : Number -> Interval -> Any
step self _ _ = unimplemented "Only intended to demonstrate an interface."
## A noise generator that implements a seeded deterministic random peterbation
of the input.
It produces what is commonly termed "white" noise, where any value in the
range has an equal chance of occurring.
type Deterministic_Random
## Step the generator to produce the next value.
Arguments:
- input: The seed number to perturb.
- interval: The interval over which the noise should be generated.
> Example
Step the generator with the input 1 and range 0 to 1
from Standard.Base.Data.Noise.Generator import Deterministic_Random
example_det_random = Deterministic_Random.step 1 (Interval.inclusive 0 1)
step : Number -> Interval -> Number
step self input interval =
max_long = Long.MAX_VALUE
seed = input.floor % max_long
gen = Random.new seed
value_range = (interval.end.n - interval.start.n).abs
offset = (interval.start.n)
gen.nextDouble
val = gen.nextDouble
(val * value_range) + offset
## Generate noise based on the input number.

View File

@ -1,56 +0,0 @@
from Standard.Base import all
import Standard.Base.Data.Interval.Bound
polyglot java import java.lang.Long
polyglot java import java.util.Random
## PRIVATE
The interface for the noise generator abstraction.
To be a valid generator, it must provide the `step` method as described
below.
type Generator
## PRIVATE
Step the generator to produce the next value..
Arguments:
- The input number, which is intended for use as a seed.
- A range for output values, which should range over the chosen output
type.
The return type may be chosen freely by the generator implementation, as
it usually depends on the generator and its intended use.
step : Number -> Interval -> Any
step self _ _ = unimplemented "Only intended to demonstrate an interface."
## A noise generator that implements a seeded deterministic random peterbation
of the input.
It produces what is commonly termed "white" noise, where any value in the
range has an equal chance of occurring.
type Deterministic_Random
## Step the generator to produce the next value.
Arguments:
- input: The seed number to perturb.
- interval: The interval over which the noise should be generated.
> Example
Step the generator with the input 1 and range 0 to 1
from Standard.Base.Data.Noise.Generator import Deterministic_Random
example_det_random = Deterministic_Random.step 1 (Interval.inclusive 0 1)
step : Number -> Interval -> Number
step self input interval =
max_long = Long.MAX_VALUE
seed = input.floor % max_long
gen = Random.new seed
value_range = (interval.end.n - interval.start.n).abs
offset = (interval.start.n)
gen.nextDouble
val = gen.nextDouble
(val * value_range) + offset

View File

@ -1,14 +1,14 @@
import project.Data.Json.Json
from project.Data.Boolean import Boolean, True, False
from project.Error.Common import Panic,Error,Illegal_Argument_Error
polyglot java import java.lang.Double
polyglot java import java.lang.Math
polyglot java import java.lang.String
polyglot java import java.lang.Long
polyglot java import java.lang.NumberFormatException
import Standard.Base.Data.Json
from Standard.Base.Data.Boolean import all
from Standard.Base.Data.Range import all
from Standard.Base.Error.Common import Panic,Error,Illegal_Argument_Error
## The root type of the Enso numeric hierarchy.
If a Number is expected, then the program can provide either a Decimal or
@ -326,7 +326,7 @@ type Number
Convert the number 8 to JSON.
8.to_json
to_json : Json.Number
to_json : Json
to_json self = Json.Number self
## A constant holding the floating-point positive infinity.
@ -597,7 +597,7 @@ type Decimal
parse : Text -> Decimal ! Parse_Error
parse text =
Panic.catch NumberFormatException (Double.parseDouble text) _->
Error.throw (Parse_Error_Data text)
Error.throw (Number_Parse_Error.Error text)
## Integer is the type of integral numbers in Enso. They are of unbounded
size and can grow as large as necessary.
@ -975,17 +975,13 @@ type Integer
parse : Text -> Text -> Integer ! Parse_Error
parse text (radix=10) =
Panic.catch NumberFormatException (Long.parseLong text radix) _->
Error.throw (Parse_Error_Data text)
# TODO Dubious constructor export
from project.Data.Numbers.Parse_Error import all
from project.Data.Numbers.Parse_Error export all
Error.throw (Number_Parse_Error.Error text)
## UNSTABLE
A syntax error when parsing a double.
type Parse_Error
Parse_Error_Data text
type Number_Parse_Error
Error text
## UNSTABLE

View File

@ -1,5 +1,9 @@
from Standard.Base import Any, Boolean, False
import Standard.Base.Meta
import project.Data.Any.Any
import project.Data.Ordering.Ordering
import project.Meta
from project.Data.Boolean import Boolean, True, False
from project.Error.Common import Error, Type_Error_Data
polyglot java import org.enso.base.Text_Utils
@ -49,3 +53,46 @@ type Text
case that of
_ : Text -> Text_Utils.equals self that
_ -> False
## Compare two texts to discover their ordering.
Arguments:
- that: The text to order `self` with respect to.
> Example
Checking how "a" orders in relation to "b".
"a".compare_to "b"
compare_to : Text -> Ordering
compare_to self that =
if that.is_nothing then Error.throw (Type_Error_Data Text that "that") else
comparison_result = Text_Utils.compare_normalized self that
Ordering.from_sign comparison_result
## ALIAS Check Emptiness
Check if `self` is empty.
! What is Empty?
Text is considered to be empty when its length is zero.
> Example
Check if the text "aaa" is empty.
"aaa".is_empty
is_empty : Boolean
is_empty self = self == ""
## ALIAS Check Non-Emptiness
Check if `self` is not empty.
! What is Not Empty?
Text is considered to be not empty when its length is greater than zero.
> Example
Check if the text "aaa" is not empty.
"aaa".not_empty
not_empty : Boolean
not_empty self = self.is_empty.not

View File

@ -458,23 +458,6 @@ Text.to_case_insensitive_key : Locale -> Text
Text.to_case_insensitive_key self locale=Locale.default =
Text_Utils.case_insensitive_key self locale.java_locale
## Compare two texts to discover their ordering.
Arguments:
- that: The text to order `self` with respect to.
> Example
Checking how "a" orders in relation to "b".
"a".compare_to "b"
Text.compare_to : Text -> Ordering
Text.compare_to self that =
if that.is_nothing then Error.throw (Type_Error_Data Text that "that") else
comparison_result = Text_Utils.compare_normalized self that
if comparison_result == 0 then Ordering.Equal else
if comparison_result < 0 then Ordering.Less else
Ordering.Greater
## Compare two texts to discover their ordering.
Arguments:
@ -492,34 +475,6 @@ Text.compare_to_ignore_case self that locale=Locale.default =
if comparison_result < 0 then Ordering.Less else
Ordering.Greater
## ALIAS Check Emptiness
Check if `self` is empty.
! What is Empty?
Text is considered to be empty when its length is zero.
> Example
Check if the text "aaa" is empty.
"aaa".is_empty
Text.is_empty : Boolean
Text.is_empty self = self == ""
## ALIAS Check Non-Emptiness
Check if `self` is not empty.
! What is Not Empty?
Text is considered to be not empty when its length is greater than zero.
> Example
Check if the text "aaa" is not empty.
"aaa".not_empty
Text.not_empty : Boolean
Text.not_empty self = self.is_empty.not
## Inserts text value at the specified index.
Arguments:
@ -870,16 +825,6 @@ Text.contains self term="" matcher=Text_Matcher.Case_Sensitive = case matcher of
match = compiled_pattern.match self Regex_Mode.First
match.is_nothing.not
## Text to JSON conversion.
> Example
Convert the text "cześć" to JSON.
"cześć".to_json
Text.to_json : Json.String
Text.to_json self = Json.String self
## Takes an integer and returns a new text, consisting of `count` concatenated
copies of `self`.
@ -1045,7 +990,6 @@ Text.drop self range=(First 1) =
Converting a text to upper case in a specified locale:
from Standard.Base import all
import Standard.Base.Data.Locale
example_case_with_locale = "i".to_case Upper (Locale.new "tr") == "İ"
Text.to_case : Case -> Locale -> Text

View File

@ -533,7 +533,7 @@ type Date
Convert the current date to JSON.
example_to_json = Date.now.to_json
to_json : Json.Object
to_json : Json
to_json self = Json.from_pairs [["type", "Date"], ["day", self.day], ["month", self.month], ["year", self.year]]
## Format this date using the provided format specifier.

View File

@ -383,7 +383,7 @@ type Date_Time
other hand, the first day of the week is Monday, and week 1 is the week
containing the first Thursday of the year. Therefore it is important to
properly specify the `locale` argument.
week_of_year : (Locale.Locale | Nothing) -> Integer
week_of_year : (Locale | Nothing) -> Integer
week_of_year self locale=Nothing =
ensure_in_epoch self <|
if locale.is_nothing then Time_Utils.get_field_as_zoneddatetime self IsoFields.WEEK_OF_WEEK_BASED_YEAR else
@ -581,7 +581,7 @@ type Date_Time
from Standard.Base import Date_Time
example_to_json = Date_Time.now.to_json
to_json : Json.Object
to_json : Json
to_json self = Json.from_pairs [["type", "Date_Time"], ["year", self.year], ["month", self.month], ["day", self.day], ["hour", self.hour], ["minute", self.minute], ["second", self.second], ["nanosecond", self.nanosecond], ["zone", self.zone]]
## Format this time as text using the specified format specifier.

View File

@ -313,7 +313,7 @@ type Duration
import Standard.Base.Data.Time.Duration
example_to_json = (Duration.seconds 10).to_json
to_json : Json.Object
to_json : Json
to_json self =
b = Vector.new_builder
b.append ["type", "Duration"]

View File

@ -292,7 +292,7 @@ type Time_Of_Day
from Standard.Base import Time_Of_Day
example_to_json = Time_Of_Day.now.to_text
to_json : Json.Object
to_json : Json
to_json self = Json.from_pairs [["type", "Time_Of_Day"], ["hour", self.hour], ["minute", self.minute], ["second", self.second], ["nanosecond", self.nanosecond]]
## Format this time of day using the provided formatter pattern.

View File

@ -735,7 +735,7 @@ type Vector a
Convert a vector of numbers to JSON.
[1, 2, 3].to_json
to_json : Json.Array
to_json : Json
to_json self = Json.Array (self.map .to_json)
## Get the first element from the vector, or an `Empty_Error` if the vector
@ -927,7 +927,7 @@ type Vector a
Converts the vector to a list with the same elements.
to_list : List
to_list self =
self.reverse.fold Nil acc-> elem-> Cons elem acc
self.reverse.fold List.Nil acc-> elem-> List.Cons elem acc
type Builder

View File

@ -115,7 +115,7 @@ type Error
import Standard.Examples
example_to_json = Examples.throw_error.to_json
to_json : Json.Object
to_json : Json
to_json self =
error_type = ["type", "Error"]
caught = self.catch

View File

@ -1,20 +1,30 @@
import project.Data.Any.Any
import project.Data.Array.Array
import project.Data.Boolean
import project.Data.List.List
import project.Data.Numbers
import project.Data.Map.Map
import project.Data.Vector.Vector
import project.Nothing.Nothing
export project.Data.Any.Any
export project.Data.Array.Array
export project.Data.List.List
export project.Data.Map.Map
export project.Data.Vector.Vector
export project.Nothing.Nothing
from project.Data.Boolean export all
from project.Data.Boolean export Boolean, True, False
from project.Data.Numbers export Number, Integer, Decimal
import project.Data.Filter_Condition.Filter_Condition
import project.Data.Index_Sub_Range.Index_Sub_Range
import project.Data.Interval.Bound
import project.Data.Interval.Interval
import project.Data.Json
import project.Data.Locale.Locale
import project.Data.Maybe.Maybe
import project.Data.Noise
import project.Data.Ordering.Ordering
import project.Data.Text.Line_Ending_Style.Line_Ending_Style
import project.Data.Text.Text_Sub_Range.Text_Sub_Range
@ -23,23 +33,23 @@ export project.Data.Filter_Condition.Filter_Condition
export project.Data.Index_Sub_Range.Index_Sub_Range
export project.Data.Interval.Bound
export project.Data.Interval.Interval
export project.Data.Json.Json
export project.Data.Locale.Locale
export project.Data.Maybe.Maybe
export project.Data.Ordering.Ordering
export project.Data.Text.Line_Ending_Style.Line_Ending_Style
export project.Data.Text.Text_Sub_Range.Text_Sub_Range
from project.Data.Json export all hiding Json_Parse_Error, No_Such_Field, Marshalling_Error
from project.Data.Noise export all hiding Noise, Generator, Deterministic_Random
from project.Data.Index_Sub_Range import First, Last
from project.Data.Index_Sub_Range export First, Last
# Not refactored modules below:
import project.Data.Json
import project.Data.List
import project.Data.Locale
import project.Data.Map
import project.Data.Noise
import project.Data.Numbers
import project.Data.Ordering.Natural_Order
import project.Data.Ordering.Sort_Direction
import project.Data.Pair
@ -85,10 +95,6 @@ import project.Data.Text.Regex
import project.Data.Text.Regex.Regex_Mode
import project.Warning
export project.Data.Json
export project.Data.Locale
export project.Data.Map
export project.Data.Ordering.Natural_Order
export project.Data.Ordering.Sort_Direction
export project.Data.Regression
@ -120,9 +126,7 @@ export project.System.File
export project.System.File.Existing_File_Behavior
export project.Warning
from project.Data.List export Nil, Cons, List
from project.Data.Numbers export all hiding Math, String, Double, Parse_Error
from project.Data.Noise export all hiding Noise
from project.Data.Pair export Pair, Pair_Data
from project.Data.Range export all
from project.Data.Text.Extensions export Text, Case, Location, Matching_Mode

View File

@ -68,6 +68,6 @@ type Response
import Standard.Examples
example_to_json = Examples.get_response.to_json
to_json : Json.Object
to_json : Json
to_json self = Json.from_pairs [["type", "Response"], ["headers", self.headers], ["body", self.body], ["code", self.code]]

View File

@ -204,7 +204,7 @@ type URI
import Standard.Examples
example_to_json = Examples.uri.to_json
to_json : Json.String
to_json : Json
to_json self = Json.String self.to_text
## Check if this URI is equal to another URI.

View File

@ -365,7 +365,7 @@ type File
import Standard.Examples
example_to_json = Examples.csv.to_json
to_json : Json.Object
to_json : Json
to_json self = Json.from_pairs [["type", "File"], ["path", self.path]]
## Checks whether the file exists.

View File

@ -1,5 +1,5 @@
from Standard.Base import all
from Standard.Base.Data.Numbers import Parse_Error_Data
from Standard.Base.Data.Numbers import Number_Parse_Error
import project.Connection.Client_Certificate.Client_Certificate
import project.Connection.Connection_Options.Connection_Options
@ -96,7 +96,7 @@ default_postgres_port =
hardcoded_port = 5432
case Environment.get "PGPORT" of
Nothing -> hardcoded_port
port -> Integer.parse port . catch Parse_Error_Data (_->hardcoded_port)
port -> Integer.parse port . catch Number_Parse_Error.Error (_->hardcoded_port)
## PRIVATE
default_postgres_database = Environment.get_or_else "PGDATABASE" ""

View File

@ -319,7 +319,7 @@ type Table
rename_columns self (column_map=(Column_Name_Mapping.By_Position ["Column"])) (on_problems=Report_Warning) = case column_map of
_ : Vector ->
self.rename_columns (Column_Name_Mapping.By_Position column_map) on_problems
_ : Map.Map ->
_ : Map ->
self.rename_columns (Column_Name_Mapping.By_Name column_map) on_problems
_ ->
new_names = Table_Helpers.rename_columns internal_columns=self.internal_columns mapping=column_map on_problems=on_problems

View File

@ -98,16 +98,16 @@ json_text = """
]
## Example JSON for working with.
json : Json.Json
json : Json
json = Json.parse json_text
## An example JSON object.
json_object : Json.Object
json_object : Json
json_object = json.items.head
## An example cons-list.
list : List
list = Cons 1 (Cons 2 (Cons 3 Nil))
list = List.Cons 1 (List.Cons 2 (List.Cons 3 List.Nil))
## A simple map that contains some numbers mapped to their word equivalents.
map : Map
@ -199,7 +199,7 @@ get_boolean : Boolean
get_boolean = False
## A simple small piece of JSON that can easily be converted into a table.
simple_table_json : Json.Json
simple_table_json : Json
simple_table_json =
row_1 = Json.from_pairs [['foo', 20], ['bar', 'baz'], ['baz', False]]
row_2 = Json.from_pairs [['bar', 'xyz'], ['baz', True]]
@ -211,7 +211,7 @@ simple_table_json_headers : Vector Text
simple_table_json_headers = ["foo", "bar", "baz"]
## Some simple GeoJSON.
geo_json : Json.Json
geo_json : Json
geo_json = Json.parse <| '''
{
"type": "FeatureCollection",

View File

@ -26,16 +26,16 @@ type Object_Type
## PRIVATE
Get the type field of a GeoJSON object.
Json.Json.get_type : Any
Json.Json.get_type self = case self of
Json.get_type : Any
Json.get_type self = case self of
Json.Object object ->
object.get_or_else "type" Nothing.to_json . unwrap
## PRIVATE
Get key-value pairs of a Feature GeoJSON object.
Json.Json.get_feature_row : Map
Json.Json.get_feature_row self =
Json.get_feature_row : Map
Json.get_feature_row self =
properties_row = self.get "properties" . get_properties_row
geometry_row = self.get "geometry" . get_geometry_row
geometry_row.fold_with_key properties_row acc-> k-> v->
@ -44,8 +44,8 @@ Json.Json.get_feature_row self =
## PRIVATE
Get column key-value pairs of a feature's "properties" object.
Json.Json.get_properties_row : Map
Json.Json.get_properties_row self = case self of
Json.get_properties_row : Map
Json.get_properties_row self = case self of
Json.Object properties -> properties.map p-> case p of
Json.Object _ -> Nothing.to_json
_ -> p
@ -53,8 +53,8 @@ Json.Json.get_properties_row self = case self of
## PRIVATE
Get column key-value pairs of a feature's "geometry" object.
Json.Json.get_geometry_row : Map
Json.Json.get_geometry_row self = case self of
Json.get_geometry_row : Map
Json.get_geometry_row self = case self of
Json.Object fields ->
geometry_type = fields.get_or_else "type" Nothing
if geometry_type == "Point".to_json then self.get_point_row else Map.empty
@ -62,8 +62,8 @@ Json.Json.get_geometry_row self = case self of
## PRIVATE
Get column key-value pairs of a "Point" geometry object.
Json.Json.get_point_row : Map
Json.Json.get_point_row self =
Json.get_point_row : Map
Json.get_point_row self =
fields = ["longitude", "latitude", "elevation"]
case self.get "coordinates" of
Json.Array coordinates ->

View File

@ -449,7 +449,7 @@ type Table
rename_columns self (column_map=(Column_Name_Mapping.By_Position ["Column"])) (on_problems=Report_Warning) = case column_map of
_ : Vector ->
self.rename_columns (Column_Name_Mapping.By_Position column_map) on_problems
_ : Map.Map ->
_ : Map ->
self.rename_columns (Column_Name_Mapping.By_Name column_map) on_problems
_ ->
new_names = Table_Helpers.rename_columns internal_columns=self.columns mapping=column_map on_problems=on_problems

View File

@ -76,8 +76,8 @@ from Standard.Geo.Geo_Json import Object_Type
json = Examples.simple_table_json
headers = Examples.simple_table_json_headers
json.to_table headers
Json.Json.to_table : Vector -> Table
Json.Json.to_table self fields=Nothing = case self of
Json.to_table : Vector -> Table
Json.to_table self fields=Nothing = case self of
Json.Array items ->
rows = items.map item-> case item of
Json.Object fs ->

View File

@ -45,12 +45,12 @@ type Bench
Arguments:
- list: The list to reverse.
reverse_list : List Any -> List
reverse_list : List -> List
reverse_list list =
go = list -> acc -> case list of
Cons h t -> @Tail_Call go t (Cons h acc)
Nil -> acc
res = go list Nil
List.Cons h t -> @Tail_Call go t (List.Cons h acc)
List.Nil -> acc
res = go list List.Nil
res
## PRIVATE
@ -59,11 +59,11 @@ reverse_list list =
Arguments:
- list: The list of numbers to sum.
sum_list : List Number -> Sum
sum_list : List -> Sum
sum_list list =
go = list -> acc -> case list of
Cons a b -> @Tail_Call go b (acc + a)
Nil -> acc
List.Cons a b -> @Tail_Call go b (acc + a)
List.Nil -> acc
res = go list 0
res
@ -74,7 +74,7 @@ sum_list list =
Arguments:
- list: The list of numbers to calculate the average of.
avg_list : List Number -> Number
avg_list : List -> Number
avg_list list = sum_list list / len_list list
## PRIVATE
@ -83,11 +83,11 @@ avg_list list = sum_list list / len_list list
Arguments:
- list: The list to calculate the length of.
len_list : List Any -> Integer
len_list : List -> Integer
len_list list =
go = list -> acc -> case list of
Cons _ b -> @Tail_Call go b (acc + 1)
Nil -> acc
List.Cons _ b -> @Tail_Call go b (acc + 1)
List.Nil -> acc
res = go list 0
res
@ -100,6 +100,6 @@ len_list list =
times : Integer -> (Integer -> Any) -> List Any
times count act =
go = results -> number -> if number == 0 then results else
@Tail_Call go (Cons (act number) results) number-1
res = reverse_list (go Nil count)
@Tail_Call go (List.Cons (act number) results) number-1
res = reverse_list (go List.Nil count)
res

View File

@ -30,11 +30,11 @@ type Test
if config.should_run_group name then
case pending of
Nothing ->
r = State.run Spec (Spec.Value name Nil) <|
r = State.run Spec (Spec.Value name List.Nil) <|
behaviors
State.get Spec
Test_Reporter.print_report r config suite.builder
new_suite = Test_Suite.Value suite.config (Cons r suite.specs) suite.builder
new_suite = Test_Suite.Value suite.config (List.Cons r suite.specs) suite.builder
State.put Test_Suite new_suite
reason ->
Test_Reporter.report_pending_group name reason config suite.builder
@ -73,7 +73,7 @@ type Test
result = pair.second
time_taken = pair.first
spec = State.get Spec
new_spec = Spec.Value spec.name (Cons (Behavior.Value label result time_taken) spec.behaviors)
new_spec = Spec.Value spec.name (List.Cons (Behavior.Value label result time_taken) spec.behaviors)
State.put Spec new_spec
## Expect a function to fail with the provided panic.

View File

@ -64,7 +64,7 @@ type Test_Suite
run ~specs config =
builder = if config.should_output_junit then StringBuilder.new else Nothing
Test_Reporter.wrap_junit_testsuites config builder <|
State.run Test_Suite (Test_Suite.Value config Nil builder) <|
State.run Test_Suite (Test_Suite.Value config List.Nil builder) <|
specs
State.get Test_Suite

View File

@ -1,5 +1,4 @@
from Standard.Base import all
import Standard.Base
## An ID used by the visualization system to identify different ways of
displaying data.
@ -18,8 +17,8 @@ type Id
Id.Builtin _ -> Nothing
Id.Library project _ ->
full_name = project.namespace + "." + project.name
Base.Json.from_pairs [["name", full_name]]
Base.Json.from_pairs [["library", project], ["name", self.name]]
Json.from_pairs [["name", full_name]]
Json.from_pairs [["library", project], ["name", self.name]]
## UNSTABLE
ADVANCED

View File

@ -344,10 +344,10 @@ class BuiltinTypesTest
val requestId = UUID.randomUUID()
val metadata = new Metadata
val idMain = metadata.addItem(39, 19)
val idMain = metadata.addItem(45, 19)
val code =
"""import Standard.Base.Data.Array
"""import Standard.Base.Data.Array.Array
|
|main =
| Array.new_1 42
@ -370,11 +370,11 @@ class BuiltinTypesTest
val requestId = UUID.randomUUID()
val metadata = new Metadata
val idMain = metadata.addItem(69, 34)
val idMain = metadata.addItem(75, 34)
val code =
"""from Standard.Base import all
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|
|main =
| Vector.from_array Array.empty

View File

@ -6,27 +6,27 @@ class AtomFixtures extends DefaultInterpreterRunner {
val million: Long = 1000000
val millionElementList = eval(
s"""|from Standard.Base.Data.List import Cons,Nil
s"""|import Standard.Base.Data.List.List
|
|main =
| generator fn acc i end = if i == end then acc else @Tail_Call generator fn (fn acc i) i+1 end
| res = generator (acc -> x -> Cons x acc) Nil 1 $million
| res = generator (acc -> x -> List.Cons x acc) List.Nil 1 $million
| res
""".stripMargin)
val generateListCode =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|main = length ->
| generator = acc -> i -> if i == 0 then acc else @Tail_Call generator (Cons i acc) (i - 1)
| generator = acc -> i -> if i == 0 then acc else @Tail_Call generator (List.Cons i acc) (i - 1)
|
| res = generator Nil length
| res = generator List.Nil length
| res
""".stripMargin
val generateList = getMain(generateListCode)
val generateListQualifiedCode =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|main = length ->
| generator = acc -> i -> if i == 0 then acc else @Tail_Call generator (List.Cons i acc) (i - 1)
@ -37,38 +37,38 @@ class AtomFixtures extends DefaultInterpreterRunner {
val generateListQualified = getMain(generateListQualifiedCode)
val reverseListCode =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|main = self -> list ->
| reverser = acc -> list -> case list of
| Cons h t -> @Tail_Call reverser (Cons h acc) t
| Nil -> acc
| List.Cons h t -> @Tail_Call reverser (List.Cons h acc) t
| List.Nil -> acc
|
| res = reverser Nil list
| res = reverser List.Nil list
| res
""".stripMargin
val reverseList = getMain(reverseListCode)
val reverseListMethodsCode =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|List.List.rev self acc = case self of
| Cons h t -> @Tail_Call t.rev (Cons h acc)
|List.rev self acc = case self of
| List.Cons h t -> @Tail_Call t.rev (List.Cons h acc)
| _ -> acc
|
|main = self -> list ->
| res = list.rev Nil
| res = list.rev List.Nil
| res
|""".stripMargin
""".stripMargin
val reverseListMethods = getMain(reverseListMethodsCode)
val sumListCode =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|main = self -> list ->
| summator = acc -> list -> case list of
| Cons h t -> @Tail_Call summator acc+h t
| Nil -> acc
| List.Cons h t -> @Tail_Call summator acc+h t
| List.Nil -> acc
|
| res = summator 0 list
| res
@ -76,11 +76,11 @@ class AtomFixtures extends DefaultInterpreterRunner {
val sumList = getMain(sumListCode)
val sumListLeftFoldCode =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|main = self -> list ->
| fold = f -> acc -> list -> case list of
| Cons h t -> @Tail_Call fold f (f acc h) t
| List.Cons h t -> @Tail_Call fold f (f acc h) t
| _ -> acc
|
| res = fold (x -> y -> x + y) 0 list
@ -89,11 +89,11 @@ class AtomFixtures extends DefaultInterpreterRunner {
val sumListLeftFold = getMain(sumListLeftFoldCode)
val sumListFallbackCode =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|main = self -> list ->
| summator = acc -> list -> case list of
| Cons h t -> @Tail_Call summator acc+h t
| List.Cons h t -> @Tail_Call summator acc+h t
| _ -> acc
|
| res = summator 0 list
@ -102,42 +102,42 @@ class AtomFixtures extends DefaultInterpreterRunner {
val sumListFallback = getMain(sumListFallbackCode)
val sumListMethodsCode =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|List.List.sum self acc = case self of
| Cons h t -> @Tail_Call t.sum h+acc
|List.sum self acc = case self of
| List.Cons h t -> @Tail_Call t.sum h+acc
| _ -> acc
|
|main = self -> list ->
| res = list.sum 0
| res
|""".stripMargin
""".stripMargin
val sumListMethods = getMain(sumListMethodsCode)
val mapReverseListCode =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|List.List.mapReverse self f acc = case self of
| Cons h t -> @Tail_Call t.mapReverse f (Cons (f h) acc)
|List.mapReverse self f acc = case self of
| List.Cons h t -> @Tail_Call t.mapReverse f (List.Cons (f h) acc)
| _ -> acc
|
|main = self -> list ->
| res = list.mapReverse (x -> x + 1) Nil
| res = list.mapReverse (x -> x + 1) List.Nil
| res
|""".stripMargin
""".stripMargin
val mapReverseList = getMain(mapReverseListCode)
val mapReverseListCurryCode =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|List.List.mapReverse self f acc = case self of
| Cons h t -> @Tail_Call t.mapReverse f (Cons (f h) acc)
|List.mapReverse self f acc = case self of
| List.Cons h t -> @Tail_Call t.mapReverse f (List.Cons (f h) acc)
| _ -> acc
|
|main = self -> list ->
| adder = x -> y -> x + y
| res = list.mapReverse (adder 1) Nil
| res = list.mapReverse (adder 1) List.Nil
| res
|""".stripMargin
""".stripMargin
val mapReverseListCurry = getMain(mapReverseListCurryCode)
}

View File

@ -47,7 +47,7 @@ public class EnsoCompilerTest {
@Test
public void testLocationsApplicationsAndMethodCalls() throws Exception {
parseTest("""
main = (2-2 == 0).if_then_else (Cons 5 6) 0
main = (2-2 == 0).if_then_else (List.Cons 5 6) 0
""", true, true, true);
}
@ -612,7 +612,7 @@ public class EnsoCompilerTest {
public void testReverseListType() throws Exception {
parseTest("""
reverse_list : List Any -> List
reverse_list list = Nil
reverse_list list = List.Nil
""");
}
@ -621,11 +621,11 @@ public class EnsoCompilerTest {
parseTest("""
reverse_list list =
go = list -> acc -> case list of
Cons h t -> go t (Cons h acc)
Cons h _ -> acc
Nil -> acc
List.Cons h t -> go t (List.Cons h acc)
List.Cons h _ -> acc
ListNil -> acc
_ -> acc
res = go list Nil
res = go list List.Nil
res
""");
}
@ -1090,11 +1090,11 @@ public class EnsoCompilerTest {
@Test
public void testAtomBenchmarks1() throws Exception {
parseTest("""
from Standard.Base.Data.List import Cons,Nil
import Standard.Base.Data.List.List
main =
generator fn acc i end = if i == end then acc else @Tail_Call generator fn (fn acc i) i+1 end
res = generator (acc -> x -> Cons x acc) Nil 1 1000000
res = generator (acc -> x -> List.Cons x acc) List.Nil 1 1000000
res
""");
}
@ -1102,14 +1102,14 @@ public class EnsoCompilerTest {
@Test
public void testAtomBenchmarks3() throws Exception {
parseTest("""
from Standard.Base.Data.List import all
import Standard.Base.Data.List.List
List.List.mapReverse self f acc = case self of
Cons h t -> @Tail_Call t.mapReverse f (Cons (f h) acc)
List.mapReverse self f acc = case self of
List.Cons h t -> @Tail_Call t.mapReverse f (List.Cons (f h) acc)
_ -> acc
main = list ->
res = list.mapReverse (x -> x + 1) Nil
res = list.mapReverse (x -> x + 1) List.Nil
res
""", true, true, false);
}

View File

@ -15,7 +15,7 @@ class CaseTest extends InterpreterTest {
"result in an error if the matched constructor isn't visible" in {
val code =
"""
|from Standard.Base.Data.List import List
|import Standard.Base.Data.List.List
|
|main =
| x = List.Cons 0 List.Nil
@ -32,7 +32,7 @@ class CaseTest extends InterpreterTest {
"result in an error if the wrong number of fields are provided" in {
val code =
"""
|from Standard.Base.Data.List import List
|import Standard.Base.Data.List.List
|
|main =
| x = List.Cons 0 List.Nil

View File

@ -54,12 +54,12 @@ class CodeLocationsTest extends InterpreterTest {
"be correct in applications and method calls" in
withLocationsInstrumenter { instrumenter =>
val code =
"""from Standard.Base.Data.List import Cons
"""import Standard.Base.Data.List.List
|
|main = (2-2 == 0).if_then_else (Cons 5 6) 0
|main = (2-2 == 0).if_then_else (List.Cons 5 6) 0
|""".stripMargin.linesIterator.mkString("\n")
instrumenter.assertNodeExists(49, 36, classOf[ApplicationNode])
instrumenter.assertNodeExists(74, 8, classOf[ApplicationNode])
instrumenter.assertNodeExists(44, 41, classOf[ApplicationNode])
instrumenter.assertNodeExists(69, 13, classOf[ApplicationNode])
eval(code)
()
}
@ -113,16 +113,16 @@ class CodeLocationsTest extends InterpreterTest {
withLocationsInstrumenter { instrumenter =>
val code =
"""
|from Standard.Base.Data.List import all
|import Standard.Base.Data.List.List
|
|main =
| x = Cons 1 2
| y = Nil
| x = List.Cons 1 2
| y = List.Nil
|
| add = a -> b -> a + b
|
| foo = x -> case x of
| Cons a b ->
| List.Cons a b ->
| z = add a b
| x = z * z
| x
@ -130,10 +130,10 @@ class CodeLocationsTest extends InterpreterTest {
|
| foo x + foo y
|""".stripMargin.linesIterator.mkString("\n")
instrumenter.assertNodeExists(121, 0, 109, 1, classOf[CaseNode])
instrumenter.assertNodeExists(167, 7, classOf[ApplicationNode])
instrumenter.assertNodeExists(187, 9, classOf[AssignmentNode])
instrumenter.assertNodeExists(224, 5, classOf[ApplicationNode])
instrumenter.assertNodeExists(127, 0, 114, 1, classOf[CaseNode])
instrumenter.assertNodeExists(178, 7, classOf[ApplicationNode])
instrumenter.assertNodeExists(198, 9, classOf[AssignmentNode])
instrumenter.assertNodeExists(235, 5, classOf[ApplicationNode])
eval(code)
()
}
@ -268,20 +268,20 @@ class CodeLocationsTest extends InterpreterTest {
instrumenter =>
val code =
"""
|from Standard.Base.Data.List import all
|import Standard.Base.Data.List.List
|
|type MyAtom
|
|main =
| f = case _ of
| Cons (Cons MyAtom Nil) Nil -> 100
| List.Cons (List.Cons MyAtom List.Nil) List.Nil -> 100
| _ -> 50
| f (Cons (Cons MyAtom Nil) Nil)
| f (List.Cons (List.Cons MyAtom List.Nil) List.Nil)
|""".stripMargin.linesIterator.mkString("\n")
instrumenter.assertNodeExists(70, 67, classOf[CaseNode])
instrumenter.assertNodeExists(75, 1, classOf[ReadLocalVariableNode])
instrumenter.assertNodeExists(118, 3, classOf[LiteralNode])
instrumenter.assertNodeExists(66, 87, classOf[CaseNode])
instrumenter.assertNodeExists(71, 1, classOf[ReadLocalVariableNode])
instrumenter.assertNodeExists(134, 3, classOf[LiteralNode])
eval(code) shouldEqual 100
}

View File

@ -15,26 +15,26 @@ class ConstructorsTest extends InterpreterTest {
): Unit = {
"dispatch to the proper match branch" in {
val patternMatchingCode =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|main =
| x = Cons 1 Nil
| x = List.Cons 1 List.Nil
| case x of
| Cons h t -> h
| Nil -> 0
| List.Cons h t -> h
| List.Nil -> 0
|""".stripMargin
eval(patternMatchingCode) shouldEqual 1
}
"work with recursion" in {
val testCode =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|main =
| genList = i -> if i == 0 then Nil else Cons i (genList (i - 1))
| genList = i -> if i == 0 then List.Nil else List.Cons i (genList (i - 1))
| sumList = list -> case list of
| Cons h t -> h + sumList t
| Nil -> 0
| List.Cons h t -> h + sumList t
| List.Nil -> 0
|
| sumList (genList 10)
|""".stripMargin
@ -43,14 +43,14 @@ class ConstructorsTest extends InterpreterTest {
"behave correctly in non-tail positions" in {
val testCode =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|main =
| add = x -> y -> x + y
| testCons = Cons 1 2
| testCons = List.Cons 1 2
|
| result = case testCons of
| Cons x y -> add x y
| List.Cons x y -> add x y
|
| result + 1
|""".stripMargin
@ -59,12 +59,12 @@ class ConstructorsTest extends InterpreterTest {
"accept a catch-all fallback clause" in {
val testCode =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|main =
| nil = Nil
| nil = List.Nil
| case nil of
| Cons _ _ -> 0
| List.Cons _ _ -> 0
| _ -> 1
|""".stripMargin
eval(testCode) shouldEqual 1
@ -72,12 +72,12 @@ class ConstructorsTest extends InterpreterTest {
"throw an exception when match fails" in {
val testCode =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|main =
| nil = Nil
| nil = List.Nil
| case nil of
| Cons h t -> 0
| List.Cons h t -> 0
|""".stripMargin
the[InterpreterException] thrownBy eval(testCode)
.call() should have message "Inexhaustive pattern match: no branch matches Nil."
@ -85,8 +85,7 @@ class ConstructorsTest extends InterpreterTest {
"be usable in code, with arbitrary definition order" in {
val testCode =
"""import Standard.Base.Nothing
|from Standard.Base.Data.List.List import all
"""import Standard.Base.Nothing.Nothing
|
|type C2
| Cons2 a b

View File

@ -40,11 +40,11 @@ class ExpressionIdTest extends InterpreterTest {
val code =
"""from Standard.Base import all
|
|main = (2-2 == 0).if_then_else (Cons 5 6) 0
|main = (2-2 == 0).if_then_else (List.Cons 5 6) 0
|""".stripMargin.linesIterator.mkString("\n")
val meta = new Metadata
val id1 = meta.addItem(38, 36)
val id2 = meta.addItem(63, 8)
val id1 = meta.addItem(38, 41)
val id2 = meta.addItem(63, 13)
instrumenter.assertNodeExists(id1, "Cons 5 6")
instrumenter.assertNodeExists(id2, "Cons 5 6")
@ -84,16 +84,16 @@ class ExpressionIdTest extends InterpreterTest {
withIdsInstrumenter { instrumenter =>
val code =
"""
|from Standard.Base.Data.List.List import all
|import Standard.Base.Data.List.List
|
|main =
| x = Cons 1 2
| y = Nil
| x = List.Cons 1 2
| y = List.Nil
|
| add = a -> b -> a + b
|
| foo = x -> case x of
| Cons a b ->
| List.Cons a b ->
| z = add a b
| x = z * z
| x
@ -102,10 +102,10 @@ class ExpressionIdTest extends InterpreterTest {
| foo x + foo y
|""".stripMargin.linesIterator.mkString("\n")
val meta = new Metadata
val id1 = meta.addItem(126, 108, "1111")
val id2 = meta.addItem(172, 7)
val id3 = meta.addItem(192, 9)
val id4 = meta.addItem(229, 5)
val id1 = meta.addItem(127, 113, "1111")
val id2 = meta.addItem(178, 7)
val id3 = meta.addItem(198, 9)
val id4 = meta.addItem(235, 5)
instrumenter.assertNodeExists(id1, "9")
instrumenter.assertNodeExists(id2, "3")

View File

@ -52,14 +52,14 @@ class GroupingTest extends InterpreterTest {
"work with pattern matches" in {
val code =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|main =
| fn = x -> case x of
| (Cons h t) -> h + fn t
| (List.Cons h t) -> h + fn t
| (_) -> 0
|
| fn (Cons 7 Nil)
| fn (List.Cons 7 List.Nil)
|""".stripMargin
eval(code) shouldEqual 7

View File

@ -66,14 +66,14 @@ class LambdaShorthandArgsTest extends InterpreterTest {
"work with case expressions" in {
val code =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|main =
| f = case _ of
| Cons a b -> 10
| Nil -> 0
| res1 = f (Cons 1 2)
| res2 = f Nil
| List.Cons a b -> 10
| List.Nil -> 0
| res1 = f (List.Cons 1 2)
| res2 = f List.Nil
| res2 - res1
|""".stripMargin

View File

@ -75,13 +75,13 @@ class LambdaTest extends InterpreterTest {
"be able to return atoms that are evaluated with oversaturated args" in {
val code =
"""from Standard.Base.Data.List import all
"""import Standard.Base.Data.List.List
|
|main =
| f = x -> Cons
| f = x -> List.Cons
| myCons = f 1 2 3
| case myCons of
| Cons h t -> h + t
| List.Cons h t -> h + t
|""".stripMargin
eval(code) shouldEqual 5
@ -89,7 +89,7 @@ class LambdaTest extends InterpreterTest {
"support the use of oversaturated args in methods" in {
val code =
"""import Standard.Base.Nothing
"""import Standard.Base.Nothing.Nothing
|
|Nothing.my_method self = 1
|

View File

@ -16,14 +16,14 @@ class PatternMatchTest extends InterpreterTest {
"work for simple patterns" in {
val code =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|main =
| f = case _ of
| Cons a _ -> a
| Nil -> -10
| List.Cons a _ -> a
| List.Nil -> -10
|
| f (Cons 10 Nil) - f Nil
| f (List.Cons 10 List.Nil) - f List.Nil
|""".stripMargin
eval(code) shouldEqual 20
@ -31,7 +31,7 @@ class PatternMatchTest extends InterpreterTest {
"work for anonymous catch-all patterns" in {
val code =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|type My_Atom
| Mk a
@ -41,7 +41,7 @@ class PatternMatchTest extends InterpreterTest {
| My_Atom.Mk a -> a
| _ -> -100
|
| f (My_Atom.Mk 50) + f Nil
| f (My_Atom.Mk 50) + f List.Nil
|""".stripMargin
eval(code) shouldEqual -50
@ -79,16 +79,16 @@ class PatternMatchTest extends InterpreterTest {
"work for level one nested patterns" in {
val code =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|type MyAtom
|
|main =
| f = case _ of
| Cons MyAtom _ -> 30
| List.Cons MyAtom _ -> 30
| _ -> -30
|
| f (Cons MyAtom Nil)
| f (List.Cons MyAtom List.Nil)
|""".stripMargin
eval(code) shouldEqual 30
@ -96,21 +96,21 @@ class PatternMatchTest extends InterpreterTest {
"work for deeply nested patterns" in {
val code =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|type MyAtom
|
|main =
| f = case _ of
| Cons (Cons MyAtom Nil) Nil -> 100
| Cons _ Nil -> 50
| List.Cons (List.Cons MyAtom List.Nil) List.Nil -> 100
| List.Cons _ List.Nil -> 50
| y -> case y of
| Cons _ Nil -> 30
| List.Cons _ List.Nil -> 30
| _ -> 0
|
| val1 = f (Cons MyAtom Nil) # 50
| val2 = f (Cons (Cons MyAtom Nil) Nil) # 100
| val3 = f 40 # 0
| val1 = f (List.Cons MyAtom List.Nil) # 50
| val2 = f (List.Cons (List.Cons MyAtom List.Nil) List.Nil) # 100
| val3 = f 40 # 0
|
| val1 + val2 + val3
|""".stripMargin
@ -120,13 +120,13 @@ class PatternMatchTest extends InterpreterTest {
"correctly result in errors for incomplete matches" in {
val code =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|type MyAtom
|
|main =
| f = case _ of
| Nil -> 30
| List.Nil -> 30
|
| f MyAtom
|""".stripMargin
@ -137,7 +137,7 @@ class PatternMatchTest extends InterpreterTest {
"work for pattern matches in pattern matches" in {
val code =
"""from Standard.Base.Data.List.List import all
"""import Standard.Base.Data.List.List
|
|type My_Atom
| Mk a
@ -149,11 +149,11 @@ class PatternMatchTest extends InterpreterTest {
|main =
| f = case _ of
| My_Atom.Mk a -> case a of
| One.Mk Nil -> 50
| One.Mk List.Nil -> 50
| _ -> 30
| _ -> 20
|
| f (My_Atom.Mk (One.Mk Nil))
| f (My_Atom.Mk (One.Mk List.Nil))
|""".stripMargin
eval(code) shouldEqual 50

View File

@ -16,7 +16,7 @@ class PolyglotTest extends InterpreterTest {
"allow calling methods on static objects" in {
val code =
"""from Standard.Base import all
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|
|main =
| class = Java.lookup_class "org.enso.example.TestClass"
@ -61,7 +61,7 @@ class PolyglotTest extends InterpreterTest {
"allow instantiating objects and calling methods on them" in {
val code =
"""from Standard.Base import all
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|
|main =
| class = Java.lookup_class "org.enso.example.TestClass"
@ -74,7 +74,7 @@ class PolyglotTest extends InterpreterTest {
"allow listing available members of an object" in {
val code =
"""from Standard.Base import all
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|
|main =
| class = Java.lookup_class "org.enso.example.TestClass"

View File

@ -68,7 +68,7 @@ class StateTest extends InterpreterTest {
"work with pattern matches" in {
val code =
"""from Standard.Base.Data.Numbers import Number
|from Standard.Base.Data.List import Nil
|import Standard.Base.Data.List.List
|import Standard.Base.IO
|import Standard.Base.Nothing
|import Standard.Base.Runtime.State
@ -78,12 +78,12 @@ class StateTest extends InterpreterTest {
| Nothing ->
| y = State.get Number
| State.put Number (y + 5)
| Nil ->
| List.Nil ->
| y = State.get Number
| State.put Number (y + 10)
|
| State.put Number 1
| matcher Nil
| matcher List.Nil
| IO.println (State.get Number)
| matcher Nothing
| IO.println (State.get Number)

View File

@ -19,7 +19,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"return success exit code (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -34,7 +34,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"return success exit code (Windows)" taggedAs OsWindows in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -49,7 +49,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"return error when creating nonexistent command" in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|main = System.create_process "nonexistentcommandxyz" Array.empty "" False False False
|""".stripMargin
@ -63,7 +63,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"return error exit code (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -79,7 +79,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"return error exit code (Windows)" taggedAs OsWindows in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -95,7 +95,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stdin chars (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -112,7 +112,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stdin chars (Windows)" taggedAs OsWindows in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -130,7 +130,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
val input = Random.nextBytes(Byte.MaxValue)
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -149,7 +149,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
pending
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -166,7 +166,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stdin unused (Windows)" taggedAs OsWindows in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -183,7 +183,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stdin empty (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -199,7 +199,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stdin empty (Windows)" taggedAs OsWindows in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -215,7 +215,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"provide stdin string (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -231,7 +231,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"provide stdin string (Windows)" taggedAs OsWindows in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -247,7 +247,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stdout chars (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -263,7 +263,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stdout chars (Windows)" taggedAs OsWindows in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -279,7 +279,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stdout binary (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -295,7 +295,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"return stdout string (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -312,7 +312,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"return stdout string (Windows)" taggedAs OsWindows in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -329,7 +329,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stderr chars (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -345,7 +345,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stderr chars (Windows)" taggedAs OsWindows in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -361,7 +361,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"redirect stderr binary (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -377,7 +377,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"return stderr string (Unix)" taggedAs OsUnix in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =
@ -393,7 +393,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
"return stderr string (Windows)" taggedAs OsWindows in {
val code =
"""import Standard.Base.System
|import Standard.Base.Data.Array
|import Standard.Base.Data.Array.Array
|from Standard.Base.Data.Boolean import all
|
|main =

View File

@ -106,15 +106,15 @@ class TextTest extends InterpreterTest {
"support converting values to display texts" in {
val code =
"""
|from Standard.Base.Data.List import Cons, Nil
|import Standard.Base.Data.List.List
|from Standard.Base.Error.Common import all
|import Standard.Base.IO
|import Standard.Base.Nothing
|
|main =
| IO.println (Cons Nothing Nothing).to_display_text
| IO.println (List.Cons Nothing Nothing).to_display_text
| IO.println (Syntax_Error_Data "foo").to_display_text
| IO.println (Type_Error_Data Nothing Nil "myvar").to_display_text
| IO.println (Type_Error_Data Nothing List.Nil "myvar").to_display_text
| IO.println (Compile_Error_Data "error :(").to_display_text
| IO.println (Inexhaustive_Pattern_Match_Error_Data 32).to_display_text
| IO.println (Arithmetic_Error_Data "cannot frobnicate quaternions").to_display_text

View File

@ -4,10 +4,10 @@ from Standard.Test import Bench
polyglot java import java.util.Random
gen_list len = 0.up_to len . fold Nil (l -> i -> Cons i+1 l)
gen_list len = 0.up_to len . fold List.Nil (l -> i -> List.Cons i+1 l)
sum_list_meta list =
nil_cons = Meta.meta Nil . constructor
nil_cons = Meta.meta List.Nil . constructor
folder acc list =
meta_list = Meta.meta list
if meta_list.constructor == nil_cons then acc else

View File

@ -10,4 +10,4 @@ prep_json size =
main =
large_json = prep_json 1000000
Bench.measure (Base.Json.parse large_json) "parse json" 10 10
Bench.measure (Json.parse large_json) "parse json" 10 10

View File

@ -1,4 +1,5 @@
from Standard.Base import all
from Standard.Base.Data.Json import Json_Parse_Error, No_Such_Field
from Standard.Test import Test, Test_Suite
import Standard.Test.Test_Result.Test_Result
@ -13,7 +14,7 @@ Text.should_fail_parsing_with self expected =
as_fail = case Json.parse self of
_ -> Test_Result.Failure "Expected a parse error, but no error reported."
result = as_fail.catch Any e-> case e of
Json.Parse_Error_Data msg ->
Json_Parse_Error.Error msg ->
if msg.contains expected then Test_Result.Success else
fail_msg = "The reported message " + msg.to_text + " did not contain " + expected.to_text + "."
Test_Result.Failure fail_msg
@ -124,6 +125,6 @@ spec =
"y": {"z": null, "w": null} }
object.get "foo" . should_equal (Json.String "bar")
object.get "bar" . should_fail_with Json.No_Such_Field_Error_Data
object.get "bar" . should_fail_with No_Such_Field.Error
main = Test_Suite.run_main spec

View File

@ -4,12 +4,12 @@ from Standard.Base.Data.List import Empty_Error
from Standard.Test import Test, Test_Suite
spec = Test.group "List" <|
l = Cons 1 <| Cons 2 <| Cons 3 <| Nil
empty = Nil
l = List.Cons 1 <| List.Cons 2 <| List.Cons 3 <| List.Nil
empty = List.Nil
Test.specify "should have properly defined length" <|
l.length.should_equal 3
Test.specify "should have well defined length when empty" <|
Nil.length.should_equal 0
List.Nil.length.should_equal 0
Test.specify "should allow folding the list with an arbitrary operation with .fold" <|
sum = l.fold 0 (+)
prod = l.fold 1 (*)
@ -41,25 +41,25 @@ spec = Test.group "List" <|
l.not_empty . should_be_true
empty.not_empty . should_be_false
Test.specify "should be convertible to a vector" <|
(Cons 3 (Cons "a" (Cons 1 Nil))).to_vector.should_equal [3, "a", 1]
(List.Cons 3 (List.Cons "a" (List.Cons 1 List.Nil))).to_vector.should_equal [3, "a", 1]
Test.specify "should allow filtering of the list using `.filter`" <|
l.filter (> 2) . should_equal (Cons 3 Nil)
l.filter (> 2) . should_equal (List.Cons 3 List.Nil)
Test.specify "should filter elements by Filter_Condition" <|
list = [1, 2, 3, 4, 5].to_list
list.filter (Filter_Condition.Greater than=3) . should_equal [4, 5].to_list
list.filter (Filter_Condition.Less than=3.5) . should_equal [1, 2, 3].to_list
list.filter (Filter_Condition.Equal to=3) . should_equal (Cons 3 Nil)
list.filter (Filter_Condition.Equal to=3) . should_equal (List.Cons 3 List.Nil)
list.filter (Filter_Condition.Not_Equal to=3) . should_equal [1, 2, 4, 5].to_list
list.filter (Filter_Condition.Equal_Or_Greater than=3) . should_equal [3, 4, 5].to_list
list.filter (Filter_Condition.Equal_Or_Less than=(-1)) . should_equal Nil
list.filter (Filter_Condition.Equal_Or_Less than=(-1)) . should_equal List.Nil
list.filter (Filter_Condition.Between 2 4) . should_equal [2, 3, 4].to_list
list.filter (Filter_Condition.Is_In [7, 3, 2]) . should_equal [2, 3].to_list
list.filter (Filter_Condition.Not_In [7, 3, 2]) . should_equal [1, 4, 5].to_list
Test.expect_panic_with (list.filter (Filter_Condition.Starts_With "a")) No_Such_Method_Error_Data
list.filter Filter_Condition.Is_True . should_equal Nil
list.filter Filter_Condition.Is_False . should_equal Nil
list.filter Filter_Condition.Is_Nothing . should_equal Nil
list.filter Filter_Condition.Is_True . should_equal List.Nil
list.filter Filter_Condition.Is_False . should_equal List.Nil
list.filter Filter_Condition.Is_Nothing . should_equal List.Nil
list.filter Filter_Condition.Not_Nothing . should_equal list
txt = ["aaa", "bbb", "abab", "cccc", "baaa", "ś"].to_list
@ -67,21 +67,21 @@ spec = Test.group "List" <|
txt.filter (Filter_Condition.Contains 's\u0301') . should_equal ["ś"].to_list
txt.filter (Filter_Condition.Starts_With "a") . should_equal ["aaa", "abab"].to_list
txt.filter (Filter_Condition.Ends_With "a") . should_equal ["aaa", "baaa"].to_list
txt.filter (Filter_Condition.Less than="a") . should_equal Nil
txt.filter (Filter_Condition.Less than="a") . should_equal List.Nil
txt.filter (Filter_Condition.Greater than="b") . should_equal ["bbb", "cccc", "baaa", "ś"].to_list
txt.filter (Filter_Condition.Between "b" "c") . should_equal ["bbb", "baaa"].to_list
Test.expect_panic_with (txt.filter (Filter_Condition.Starts_With 42)) Unsupported_Argument_Types_Data
["", Nothing, " ", "a"].to_list.filter (Filter_Condition.Is_Empty) . should_equal ["", Nothing].to_list
["", Nothing, " ", "a"].to_list.filter (Filter_Condition.Not_Empty) . should_equal [" ", "a"].to_list
["abab", "aaabaaaa", "ba"].to_list.filter (Filter_Condition.Like "ba") . should_equal (Cons "ba" Nil)
["abab", "aaabaaaa", "ba"].to_list.filter (Filter_Condition.Like "ba") . should_equal (List.Cons "ba" List.Nil)
["abab", "aaabaaaa"].to_list.filter (Filter_Condition.Like "_ba_") . should_equal ["abab"].to_list
["abab", "aaabaaaa"].to_list.filter (Filter_Condition.Like "%ba__%") . should_equal ["aaabaaaa"].to_list
["abab", "aaabaaaa"].to_list.filter (Filter_Condition.Not_Like "%ba%") . should_equal Nil
["abab", "aaabaaaa"].to_list.filter (Filter_Condition.Not_Like "%ba%") . should_equal List.Nil
mixed = [1, Nothing, "b"].to_list
mixed.filter Filter_Condition.Is_Nothing . should_equal (Cons Nothing Nil)
mixed.filter Filter_Condition.Not_Nothing . should_equal (Cons 1 (Cons "b" Nil))
mixed.filter Filter_Condition.Is_Nothing . should_equal (List.Cons Nothing List.Nil)
mixed.filter Filter_Condition.Not_Nothing . should_equal (List.Cons 1 (List.Cons "b" List.Nil))
bools = [True, False, Nothing, True].to_list
bools.filter Filter_Condition.Is_True . should_equal [True, True].to_list
@ -98,19 +98,19 @@ spec = Test.group "List" <|
Test.specify "should allow reversing with .reverse" <|
l.reverse.head.should_equal 3
Test.specify "should allow dropping elements from the left with `.drop`" <|
l.drop_start 1 . should_equal (Cons 2 (Cons 3 Nil))
empty.drop_start 1 . should_equal Nil
l.drop_start 1 . should_equal (List.Cons 2 (List.Cons 3 List.Nil))
empty.drop_start 1 . should_equal List.Nil
Test.specify "should allow taking elements from the left with `.take_start`" <|
l.take_start 2 . should_equal (Cons 1 (Cons 2 Nil))
empty.take_start 2 . should_equal Nil
l.take_start 2 . should_equal (List.Cons 1 (List.Cons 2 List.Nil))
empty.take_start 2 . should_equal List.Nil
Test.specify "should allow getting the head of the list with `.head`" <|
l.head . should_equal 1
empty.head.should_fail_with Empty_Error
Test.specify "should allow getting the tail of the list with `.tail`" <|
l.tail . should_equal (Cons 2 (Cons 3 Nil))
l.tail . should_equal (List.Cons 2 (List.Cons 3 List.Nil))
empty.tail.should_fail_with Empty_Error
Test.specify "should allow getting the init of the list with `.init`" <|
l.init . should_equal (Cons 1 (Cons 2 Nil))
l.init . should_equal (List.Cons 1 (List.Cons 2 List.Nil))
empty.init.should_fail_with Empty_Error
Test.specify "should allow getting the last element of the list with `.last`" <|
l.last . should_equal 3
@ -119,7 +119,7 @@ spec = Test.group "List" <|
l.first . should_equal 1
empty.first.should_fail_with Empty_Error
Test.specify "should allow getting the tail of the list with `.rest`" <|
l.rest . should_equal (Cons 2 (Cons 3 Nil))
l.rest . should_equal (List.Cons 2 (List.Cons 3 List.Nil))
empty.rest.should_fail_with Empty_Error
main = Test_Suite.run_main spec

View File

@ -1,6 +1,6 @@
from Standard.Base import all
from Standard.Base.Data.Map import No_Value_For_Key_Error_Data
from Standard.Base.Data.Map import No_Value_For_Key
from Standard.Test import Test, Test_Suite
@ -45,7 +45,7 @@ spec = Test.group "Maps" <|
m.get "foo" . should_equal 134
m.get "bar" . should_equal 654
m.get "baz" . should_equal "spam"
(m.get "nope").should_fail_with No_Value_For_Key_Error_Data
(m.get "nope").should_fail_with No_Value_For_Key.Error
Test.specify "should support get_or_else" <|
m = Map.empty . insert 2 3
m.get_or_else 2 0 . should_equal 3

View File

@ -1,18 +1,19 @@
from Standard.Base import all
import Standard.Base.Data.Noise.Generator
import Standard.Base.Data.Noise.Deterministic_Random
import Standard.Base.Error.Common
from Standard.Test import Test, Test_Suite
spec =
Test.group "Generator Interface" <|
gen = Generator.Generator
gen = Generator
Test.specify "should not be invokable" <|
interval = Interval.inclusive 0 1
Test.expect_panic_with (gen.step 1 interval) Common.Unimplemented_Error_Data
Test.group "Deterministic Random Noise Generator" <|
gen = Generator.Deterministic_Random
gen = Deterministic_Random
Test.specify "should always return the same output for the same input" <|
interval = Interval.inclusive 0 1
values = Vector.fill 10000 1 . map (gen.step _ interval)

View File

@ -1,6 +1,6 @@
from Standard.Base import all
from Standard.Base.Data.Numbers import Parse_Error_Data
from Standard.Base.Data.Numbers import Number_Parse_Error
from Standard.Test import Test, Test_Suite
@ -181,28 +181,28 @@ spec =
Integer.parse "-1234567" . should_equal -1234567
Integer.parse "00000" . should_equal 0
Integer.parse "00000123" . should_equal 123
Integer.parse "123.45" . should_fail_with Parse_Error_Data
Integer.parse "123A" . should_fail_with Parse_Error_Data
Integer.parse "aaaa" . should_fail_with Parse_Error_Data
Integer.parse "123.45" . should_fail_with Number_Parse_Error.Error
Integer.parse "123A" . should_fail_with Number_Parse_Error.Error
Integer.parse "aaaa" . should_fail_with Number_Parse_Error.Error
Test.specify "should be able to parse alternate bases" <|
Integer.parse "1245623" 8 . should_equal 347027
Integer.parse "-1245623" 8 . should_equal -347027
Integer.parse "0001245623" 8 . should_equal 347027
Integer.parse "00000" 8 . should_equal 0
Integer.parse "9847" 8 . should_fail_with Parse_Error_Data
Integer.parse "8479" 8 . should_fail_with Parse_Error_Data
Integer.parse "9847" 8 . should_fail_with Number_Parse_Error.Error
Integer.parse "8479" 8 . should_fail_with Number_Parse_Error.Error
Integer.parse "ABC123" 16 . should_equal 11256099
Integer.parse "123ABC" 16 . should_equal 1194684
Integer.parse "123aBc" 16 . should_equal 1194684
Integer.parse "-ABC123" 16 . should_equal -11256099
Integer.parse "00000ABC123" 16 . should_equal 11256099
Integer.parse "123aBcG" 16 . should_fail_with Parse_Error_Data
Integer.parse "123aBcG" 16 . should_fail_with Number_Parse_Error.Error
Integer.parse "10101010" 2 . should_equal 170
Integer.parse "00001111" 2 . should_equal 15
Integer.parse "-10101010" 2 . should_equal -170
Integer.parse "-101021010" 2 . should_fail_with Parse_Error_Data
Integer.parse "123" 128 . should_fail_with Parse_Error_Data
Integer.parse "-101021010" 2 . should_fail_with Number_Parse_Error.Error
Integer.parse "123" 128 . should_fail_with Number_Parse_Error.Error
Test.group "Decimals" <|
@ -218,7 +218,7 @@ spec =
Decimal.parse "-98.5" . should_equal -98.5
Decimal.parse "000000" . should_equal 0
Decimal.parse "000000.0001" . should_equal 0.0001
Decimal.parse "aaaa" . should_fail_with Parse_Error_Data
Decimal.parse "aaaa" . should_fail_with Number_Parse_Error.Error
Test.group "Numbers" <|

View File

@ -287,9 +287,9 @@ spec = Test.group "Vectors" <|
concat.should_equal [1, 2, 3, 4, 5, 6]
Test.specify "should be convertible to a list" <|
[].to_list . should_equal Nil
["A"].to_list . should_equal (Cons "A" Nil)
[1, 2, "B", 3].to_list . should_equal (Cons 1 (Cons 2 (Cons "B" (Cons 3 Nil))))
[].to_list . should_equal List.Nil
["A"].to_list . should_equal (List.Cons "A" List.Nil)
[1, 2, "B", 3].to_list . should_equal (List.Cons 1 (List.Cons 2 (List.Cons "B" (List.Cons 3 List.Nil))))
Test.specify "Vector slice should return a Vector" <|
vec = [1, 2, 3, 4, 5, 6]

View File

@ -201,21 +201,21 @@ spec = Test.group "Pattern Matches" <|
'\u0065\u{301}' -> Nothing
_ -> Test.fail "Expected value to match constant."
Test.specify "should be able to match on literal values nested in constructors" <|
value_1 = Cons 42 Nil
value_2 = Cons (Cons 42 Nil) Nil
value_1 = List.Cons 42 List.Nil
value_2 = List.Cons (List.Cons 42 List.Nil) List.Nil
case value_1 of
42 -> Test.fail "Expected value to match constant."
Cons (Cons 1 Nil) Nil -> Test.fail "Expected value to match constant."
Cons 1 Nil -> Test.fail "Expected value to match constant."
Cons 42 Nil -> Nothing
_ -> Test.fail "Expected value to match constant."
42 -> Test.fail "Expected value to match constant."
List.Cons (List.Cons 1 List.Nil) List.Nil -> Test.fail "Expected value to match constant."
List.Cons 1 List.Nil -> Test.fail "Expected value to match constant."
List.Cons 42 List.Nil -> Nothing
_ -> Test.fail "Expected value to match constant."
case value_2 of
42 -> Test.fail "Expected value to match constant."
Cons (Cons 1 Nil) Nil -> Test.fail "Expected value to match constant."
Cons (Cons a Nil) Nil -> if a == 42 then Nothing else Test.fail "Expected variable to bind to 42"
Cons 1 Nil -> Test.fail "Expected value to match constant."
Cons _ Nil -> Test.fail "Expected value to match constant."
_ -> Test.fail "Expected value to match constant."
42 -> Test.fail "Expected value to match constant."
List.Cons (List.Cons 1 List.Nil) List.Nil -> Test.fail "Expected value to match constant."
List.Cons (List.Cons a List.Nil) List.Nil -> if a == 42 then Nothing else Test.fail "Expected variable to bind to 42"
List.Cons 1 List.Nil -> Test.fail "Expected value to match constant."
List.Cons _ List.Nil -> Test.fail "Expected value to match constant."
_ -> Test.fail "Expected value to match constant."
Test.specify "should be able to match on module rather than a type" <|
case Vector_Module of

View File

@ -110,7 +110,7 @@ spec = Test.group "Meta-Value Manipulation" <|
n_2 . should_equal_type Decimal
n_2 . should_not_equal_type Integer
n_3 = Meta.type_of (Long.MAX_VALUE * 2)
n_3 = Meta.type_of (JLong.MAX_VALUE * 2)
n_3 . should_equal_type Integer
n_3 . should_not_equal_type Decimal

View File

@ -3,6 +3,6 @@ type Array
at self index = @Builtin_Method "Array.at"
length self = @Builtin_Method "Array.length"
new_1 item_1 = @Builtin_Method "Array.new_1"
new_2 item_1 item_2 = @Builtin_Method "Array.new_2"
empty = @Builtin_Method "Array.empty"
new_1 item_1 = @Builtin_Method "Array.new_1"
new_2 item_1 item_2 = @Builtin_Method "Array.new_2"
empty = @Builtin_Method "Array.empty"

View File

@ -1,6 +1,3 @@
from project.Data.List.List import all
from project.Data.List.List export all
type List
Nil
Cons x xs

View File

@ -1,4 +1,3 @@
@Builtin_Type
type Vector a
from_array array = @Builtin_Method "Vector.from_array"
from_array array = @Builtin_Method "Vector.from_array"

View File

@ -4,23 +4,23 @@ export project.IO
import project.Error.Common
from project.Error.Common export all
import project.Data.Any
from project.Data.Any export Any
import project.Data.Any.Any
export project.Data.Any.Any
import project.Data.Array
from project.Data.Array export Array
import project.Data.Array.Array
export project.Data.Array.Array
import project.Data.Boolean
from project.Data.Boolean export Boolean, True, False
import project.Data.List
from project.Data.List export Nil, Cons, List
import project.Data.List.List
export project.Data.List.List
import project.Data.Numbers
from project.Data.Numbers export Number
import project.Data.Numbers.Number
export project.Data.Numbers.Number
import project.Data.Vector
export project.Data.Vector
import project.Data.Vector.Vector
export project.Data.Vector.Vector
import project.Polyglot
export project.Polyglot