Skip to content

Commit

Permalink
Use long names for string and numbers
Browse files Browse the repository at this point in the history
Rename the builtin `Num` and `Str` types to `Number` and `String`, and
use long names on a number of related functions and stdlib modules for
consistency. This is a breaking syntax change.
  • Loading branch information
yannham committed Mar 8, 2023
1 parent 44f7222 commit 030c71e
Show file tree
Hide file tree
Showing 85 changed files with 920 additions and 904 deletions.
4 changes: 2 additions & 2 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ with a comment declaring the expected behaviour. For example
# test: blame
let Even = fun label value =>
if builtin.is_num value && value % 2 == 0 then
if builtin.is_number value && value % 2 == 0 then
value
else
contract.blame label in
let DivBy3 = fun label value =>
if builtin.is_num value && value % 3 == 0 then
if builtin.is_number value && value % 3 == 0 then
value
else
contract.blame label in
Expand Down
2 changes: 1 addition & 1 deletion benches/arrays/fold.ncl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let letter | Num -> string.CharLiteral = fun n =>
let letter | Number -> string.CharLiteral = fun n =>
string.code "a" + (n % 26)
|> string.from_code in

Expand Down
2 changes: 1 addition & 1 deletion benches/arrays/generate.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let g = fun n => n*2 + 5 in
run = fun n => generate n g,
},
checked = {
generate_with_contract | forall a. Num -> (Num -> a) -> Array a = fun n g =>
generate_with_contract | forall a. Number -> (Number -> a) -> Array a = fun n g =>
if n == 0 then []
else generate_with_contract (n - 1) g @ [g n],

Expand Down
6 changes: 3 additions & 3 deletions benches/arrays/primes.ncl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let range
| doc "Generate an array of integers in the range [`start`, `end`)."
| Num -> Num -> Array Num
| Number -> Number -> Array Number
= fun start end =>
if end <= start then
[]
Expand All @@ -17,9 +17,9 @@ let Prime = contract.from_predicate is_prime in

let primes
| doc "Generate `max` primes using Sieve of Eratosthenes."
| Num -> Array Prime
| Number -> Array Prime
= fun max =>
let limit = num.pow max (1 / 2) in # sqrt(max)
let limit = number.pow max (1 / 2) in # sqrt(max)
let drop_multiples = fun x xs =>
let to_drop = max
|> array.generate (fun y => (y + 2) * x)
Expand Down
4 changes: 2 additions & 2 deletions benches/arrays/random.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ let mgc
# of the 2021 paper "Computationally Easy, Spectrally Good Multipliers for
# Congruential Pseudorandom Number Generators", by Guy Steele and Sebastiano Vigna.
# But, they cannot be used because they require bit-shifting to select the 32 MSBs.
# let params = { m = num.pow 2 32, a = 2480367069 } in
# let params = { m = number.pow 2 32, a = 2480367069 } in

# These parameters are from the "Numerical Recipes" book.
let params = { m = num.pow 2 32, a = 1664525, c = 1013904223 } in
let params = { m = number.pow 2 32, a = 1664525, c = 1013904223 } in

let rec array_random = fun init n =>
if n == 0 then [init]
Expand Down
2 changes: 1 addition & 1 deletion benches/arrays/sum.ncl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let rec sum
| Array Num -> Num
| Array Number -> Number
= fun xs =>
if array.length xs == 0 then 0
else array.first xs + sum (array.drop_first xs)
Expand Down
2 changes: 1 addition & 1 deletion benches/mantis/deploy.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun vars =>
"eu-west-2"])
| default = ["eu-central-1", "us-east-2"],
fqdn = "mantis.ws",
networkConfig | Str
networkConfig | String
| default = m%"
mantis.blockchains.testnet-internal-nomad.bootstrap-nodes = [
%{string.join ",\n" bootstrapNodes."%{vars.namespace}"})
Expand Down
18 changes: 9 additions & 9 deletions benches/mantis/jobs/mantis.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ let lib = import "../lib.ncl" in
let baseTags = [""] in

let Params = {
count | num.Nat
count | number.Nat
| default = 5,
role | [| `passive, `miner, `backup |],
datacenters | Dyn,
job | Dyn,
namespace | Str,
logLevel | Str,
mantisRev | Str,
fqdn | Str,
loggers | {_: Str},
namespace | String,
logLevel | String,
mantisRev | String,
fqdn | String,
loggers | {_: String},
network | lib.contracts.OneOf ["testnet-internal-nomad", "etc"]
| default = "testnet-internal-nomad",
networkConfig | Str,
networkConfig | String,

fastSync | Bool
| default = false,
reschedule | {..}
#{_ : lib.contracts.PseudoOr [
# lib.contracts.OrableFromPred builtin.is_str,
# lib.contracts.OrableFromPred builtin.is_num,
# lib.contracts.OrableFromPred builtin.is_string,
# lib.contracts.OrableFromPred builtin.is_number,
# lib.contracts.OrableFromPred builtin.is_bool,
# {
# pred = builtin.is_record,
Expand Down
2 changes: 1 addition & 1 deletion benches/mantis/lib.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
SmallerEq = fun x => contract.from_predicate (fun y => y <= x),
MatchRegexp = fun regex label value =>
let str_match = string.is_match regex in
if builtin.is_str value then
if builtin.is_string value then
if str_match value then
value
else
Expand Down
Loading

0 comments on commit 030c71e

Please sign in to comment.