s/Len/Nat in builtin docs

This commit is contained in:
Richard Feldman 2020-12-31 16:02:08 -05:00
parent fd60e1c67f
commit d388ef39e4
4 changed files with 39 additions and 39 deletions

View file

@ -24,15 +24,15 @@ interface List2
## to be created just fine, but then crashing later.)
##
## > The theoretical maximum length for a list created in Roc is
## > #Int.highestLen divided by 2. Attempting to create a list bigger than that
## > #Int.maxNat divided by 2. Attempting to create a list bigger than that
## > in Roc code will always fail, although in practice it is likely to fail
## > at much smaller lengths due to insufficient memory being available.
##
## ## Performance Details
##
## Under the hood, a list is a record containing a `len : Len` field as well
## Under the hood, a list is a record containing a `len : Nat` field as well
## as a pointer to a reference count and a flat array of bytes. Unique lists
## store a capacity #Len instead of a reference count.
## store a capacity #Nat instead of a reference count.
##
## ## Shared Lists
##
@ -166,7 +166,7 @@ empty : List *
## Returns a list with the given length, where every element is the given value.
##
##
repeat : elem, Len -> List elem
repeat : elem, Nat -> List elem
## Returns a list of all the integers between one and another,
## including both of the given numbers.
@ -226,11 +226,11 @@ mapOks : List before, (before -> Result after *) -> List after
## In particular when updating nested collections, this is potentially much more
## efficient than using #List.get to obtain the element, transforming it,
## and then putting it back in the same place.
update : List elem, Len, (elem -> elem) -> List elem
update : List elem, Nat, (elem -> elem) -> List elem
## A more flexible version of #List.update, which returns an "updater" function
## that lets you delay performing the update until later.
updater : List elem, Len -> { elem, new : elem -> List elem }
updater : List elem, Nat -> { elem, new : elem -> List elem }
## If all the elements in the list are #Ok, return a new list containing the
## contents of those #Ok tags. If any elements are #Err, return #Err.
@ -354,7 +354,7 @@ first : List elem -> Result elem [ ListWasEmpty ]*
## Returns the last element in the list, or `ListWasEmpty` if it was empty.
last : List elem -> Result elem [ ListWasEmpty ]*
get : List elem, Len -> Result elem [ OutOfBounds ]*
get : List elem, Nat -> Result elem [ OutOfBounds ]*
max : List (Num a) -> Result (Num a) [ ListWasEmpty ]*
@ -370,14 +370,14 @@ min : List (Num a) -> Result (Num a) [ ListWasEmpty ]*
## list unmodified.
##
## To drop the element at a given index, instead of replacing it, see #List.drop.
put : List elem, Len, elem -> List elem
put : List elem, Nat, elem -> List elem
## Drops the element at the given index from the list.
##
## This has no effect if the given index is outside the bounds of the list.
##
## To replace the element at a given index, instead of dropping it, see #List.put.
drop : List elem, Len -> List elem
drop : List elem, Nat -> List elem
## Adds a new element to the end of the list.
##
@ -482,7 +482,7 @@ dropFirst : List elem -> Result { first: elem, others : List elem } [ ListWasEmp
## In fact, `List.takeFirst 1 list` runs faster than `List.first list` when given
## a Unique list, because #List.first returns the first element as well -
## which introduces a conditional bounds check as well as a memory load.
takeFirst : List elem, Len -> List elem
takeFirst : List elem, Nat -> List elem
## Returns the given number of elements from the end of the list.
##
@ -510,7 +510,7 @@ takeFirst : List elem, Len -> List elem
## In fact, `List.takeLast 1 list` runs faster than `List.first list` when given
## a Unique list, because #List.first returns the first element as well -
## which introduces a conditional bounds check as well as a memory load.
takeLast : List elem, Len -> List elem
takeLast : List elem, Nat -> List elem
## Deconstruct
@ -521,7 +521,7 @@ takeLast : List elem, Len -> List elem
## than the given index, # and the `others` list will be all the others. (This
## means if you give an index of 0, the `before` list will be empty and the
## `others` list will have the same elements as the original list.)
split : List elem, Len -> { before: List elem, others: List elem }
split : List elem, Nat -> { before: List elem, others: List elem }
## Returns a subsection of the given list, beginning at the `start` index and
## including a total of `len` elements.
@ -538,7 +538,7 @@ split : List elem, Len -> { before: List elem, others: List elem }
## > matter how long the list is, #List.takeLast can do that more efficiently.
##
## Some languages have a function called **`slice`** which works similarly to this.
sublist : List elem, { start : Len, len : Len } -> List elem
sublist : List elem, { start : Nat, len : Nat } -> List elem
## Build a value using each element in the list.
##
@ -605,7 +605,7 @@ walkBackwardsUntil : List elem, { start : state, step : (state, elem -> [ Contin
## One #List can store up to 2,147,483,648 elements (just over 2 billion), which
## is exactly equal to the highest valid #I32 value. This means the #U32 this function
## returns can always be safely converted to an #I32 without losing any data.
len : List * -> Len
len : List * -> Nat
isEmpty : List * -> Bool

View file

@ -24,9 +24,9 @@ interface Num2
## a more specific type based on how they're used.
##
## For example, in `(1 + List.len myList)`, the `1` has the type `Num *` at first,
## but because `List.len` returns a `Len`, the `1` ends up changing from
## `Num *` to the more specific `Len`, and the expression as a whole
## ends up having the type `Len`.
## but because `List.len` returns a `Nat`, the `1` ends up changing from
## `Num *` to the more specific `Nat`, and the expression as a whole
## ends up having the type `Nat`.
##
## Sometimes number literals don't become more specific. For example,
## the #Num.toStr function has the type `Num * -> Str`. This means that
@ -47,7 +47,7 @@ interface Num2
##
## * `215u8` is a `215` value of type #U8
## * `76.4f32` is a `76.4` value of type #F32
## * `12345ulen` is a `12345` value of type `#Len`
## * `12345ulen` is a `12345` value of type #Nat
##
## In practice, these are rarely needed. It's most common to write
## number literals without any suffix.
@ -116,7 +116,7 @@ U64 : Int @U64
I128 : Int @I128
U128 : Int @U128
Ilen : Int @Ilen
Len : Int @Len
Nat : Int @Nat
## A 64-bit signed integer. All number literals without decimal points are compatible with #Int values.
##
@ -176,15 +176,15 @@ Len : Int @Len
## | ` (over 340 undecillion) 0` | #U128 | 16 Bytes |
## | ` 340_282_366_920_938_463_463_374_607_431_768_211_455` | | |
##
## Roc also has one variable-size integer type: #Len. The size of #Len is equal
## Roc also has one variable-size integer type: #Nat. The size of #Nat is equal
## to the size of a memory address, which varies by system. For example, when
## compiling for a 64-bit system, #Len is the same as #U64. When compiling for a
## compiling for a 64-bit system, #Nat is the same as #U64. When compiling for a
## 32-bit system, it's the same as #U32.
##
## A common use for #Len is to store the length ("len" for short) of a
## A common use for #Nat is to store the length ("len" for short) of a
## collection like #List, #Set, or #Map. 64-bit systems can represent longer
## lists in memory than 32-bit sytems can, which is why the length of a list
## is represented as a #Len in Roc.
## is represented as a #Nat in Roc.
##
## If any operation would result in an #Int that is either too big
## or too small to fit in that range (e.g. calling `Int.maxI32 + 1`),
@ -475,22 +475,22 @@ ceil : Float * -> Int *
floor : Float * -> Int *
trunc : Float * -> Int *
## Convert an #Int to a #Len. If the given number doesn't fit in #Len, it will be truncated.
## Since #Len has a different maximum number depending on the system you're building
## Convert an #Int to a #Nat. If the given number doesn't fit in #Nat, it will be truncated.
## Since #Nat has a different maximum number depending on the system you're building
## for, this may give a different answer on different systems.
##
## For example, on a 32-bit sytem, #Num.maxLen will return the same answer as
## #Num.maxU32. This means that calling `Num.toLen 9_000_000_000` on a 32-bit
## For example, on a 32-bit sytem, #Num.maxNat will return the same answer as
## #Num.maxU32. This means that calling `Num.toNat 9_000_000_000` on a 32-bit
## system will return #Num.maxU32 instead of 9 billion, because 9 billion is
## higher than #Num.maxU32 and will not fit in a #Len on a 32-bit system.
## higher than #Num.maxU32 and will not fit in a #Nat on a 32-bit system.
##
## However, calling `Num.toLen 9_000_000_000` on a 64-bit system will return
## the #Len value of 9_000_000_000. This is because on a 64-bit system, #Len can
## However, calling `Num.toNat 9_000_000_000` on a 64-bit system will return
## the #Nat value of 9_000_000_000. This is because on a 64-bit system, #Nat can
## hold up to #Num.maxU64, and 9_000_000_000 is lower than #Num.maxU64.
##
## To convert a #Float to a #Len, first call either #Num.round, #Num.ceil, or #Num.floor
## To convert a #Float to a #Nat, first call either #Num.round, #Num.ceil, or #Num.floor
## on it, then call this on the resulting #Int.
toLen : Int * -> Len
toNat : Int * -> Nat
## Convert an #Int to an #I8. If the given number doesn't fit in #I8, it will be truncated.
##
@ -606,20 +606,20 @@ hash64 : a -> U64
## Limits
## The highest number that can be stored in a #Len without overflowing its
## The highest number that can be stored in a #Nat without overflowing its
## available memory and crashing.
##
## Note that this number varies by systems. For example, when building for a
## 64-bit system, this will be equal to #Num.maxU64, but when building for a
## 32-bit system, this will be equal to #Num.maxU32.
maxLen : Len
maxNat : Nat
## The number zero.
##
## #Num.minLen is the lowest number that can be stored in a #Len, which is zero
## because #Len is [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations),
## #Num.minNat is the lowest number that can be stored in a #Nat, which is zero
## because #Nat is [unsigned](https://en.wikipedia.org/wiki/Signed_number_representations),
## and zero is the lowest unsigned number. Unsigned numbers cannot be negative.
minLen : Len
minNat : Nat
## The highest number that can be stored in an #I32 without overflowing its
## available memory and crashing.

View file

@ -10,7 +10,7 @@ empty : Set *
isEmpty : Set * -> Bool
len : Set * -> Len
len : Set * -> Nat
# TODO: removed `'` from signature because parser does not support it yet
# Original signature: `add : Set 'elem, 'elem -> Set 'elem`

View file

@ -111,7 +111,7 @@ Str2 : [ @Str ]
##
## If you want to keep all the digits, passing the same float to #Str.num
## will do that.
decimal : Float *, Len -> Str
decimal : Float *, Nat -> Str
## Split a string around a separator.
##