prelude
The basic types and what is done with them: Nat, Empty, pairs, Maybe,
Either, Bytes (bytes has its operations); Bool, Unit and lists
(builtin has them), lists’ :: and ++ (their other
operations are List’s); numbers and strings, by the
primitives, with their operators.
Nat
data Nat = Zero | Succ NatThe natural numbers.
Empty
data EmptyPair
data Pair a b = MkPair a bMaybe
data Maybe a = Nothing | Just aEither
data Either a b = Left a | Right bBytes
data BytesBytes, not changed once made: a type of its own beside String,
written b[...], whose operations are bytes’s (import bytes as Bytes), but its equality, instanceEqualityBytes, its Debug,
instanceDebugBytes, and its Show, instanceShowBytes
Bits
data BitsBits, a bitstring of any length, not changed once made: a type of
its own beside Bytes (which are whole bytes), written b[...]
where its segments are not whole bytes (b[5::3]), whose operations
are bits’s (import bits as Bits), but its equality,
instanceEqualityBits, its Debug, instanceDebugBits, and its
Show, instanceShowBits
::
(::) : {a : Type} -> a -> List a -> List ax :: xs is Cons x xs; a pattern too, as it only names the tag
id
id : {a : Type} -> a -> aconst
const : {a b : Type} -> a -> b -> aflip
flip : {a b c : Type} -> (a -> b -> c) -> b -> a -> ccompose
compose : {a b c : Type} -> (b -> c) -> (a -> b) -> a -> c$
($) : {a b : Type} -> (a -> b) -> a -> bApplication, loosest: f $ g $ x is f (g x).
not
not : Bool -> Bool&&
(&&) : Bool -> Bool -> Bool||
(||) : Bool -> Bool -> BoolOrdering
data Ordering = LT | EQ | GTHow one value is to another: less, equal, or greater.
Equality
theory Equality a where equal : a -> a -> BoolA type’s equality: a function that compares values of a type it does
not know asks for it, {{eq : Equality a}}, and is given the instance in
scope of the type it is used at — the prelude’s of Int, Float64,
String, Rune, Bool, Unit and Ordering, and of a List, a
Maybe, a Pair and an Either of types that have one, found by
finding theirs; a fixed-width type’s module’s of its own.
==
(==) : {a : Type} -> {{eq : Equality a}} -> a -> a -> Bool/=
(/=) : {a : Type} -> {{eq : Equality a}} -> a -> a -> BoolOrder
theory Order a where eq : Equality a compare : a -> a -> Ordering lt : a -> a -> Bool le : a -> a -> BoolA type’s order: its equality (eq), how two values are (compare),
and whether one is less than the other, or not greater (lt, le:
what < and <= are, as fast as the type has them) — the prelude’s
of Int,
Float64, String, Rune, Bool, Unit and Ordering, and of a
List, a Maybe and a Pair of types that have one; a fixed-width
type’s module’s of its own.
compare
compare : {a : Type} -> {{ord : Order a}} -> a -> a -> Ordering<
(<) : {a : Type} -> {{ord : Order a}} -> a -> a -> Bool<=
(<=) : {a : Type} -> {{ord : Order a}} -> a -> a -> Bool>
(>) : {a : Type} -> {{ord : Order a}} -> a -> a -> Bool>=
(>=) : {a : Type} -> {{ord : Order a}} -> a -> a -> Boolmin
min : {a : Type} -> {{ord : Order a}} -> a -> a -> aThe lesser of the two (the first, of two as great).
max
max : {a : Type} -> {{ord : Order a}} -> a -> a -> aThe greater of the two (the second, of two as great).
Addition
theory Addition a where add : a -> a -> a+
(+) : {a : Type} -> {{add : Addition a}} -> a -> a -> aSubtraction
theory Subtraction a where sub : a -> a -> a-
(-) : {a : Type} -> {{sub : Subtraction a}} -> a -> a -> aMultiplication
theory Multiplication a where mul : a -> a -> a*
(*) : {a : Type} -> {{mul : Multiplication a}} -> a -> a -> aDivision
theory Division a where div : a -> a -> aA type’s division, total: by zero, zero, as Lean’s and Coq’s are —
no division abandons, and x / 0 is 0 (exception’s divOrThrow
throws instead). Not a float’s: /. is a float’s, IEEE’s.
/
(/) : {a : Type} -> {{div : Division a}} -> a -> a -> aRemainder
theory Remainder a where mod : a -> a -> aThe remainder of a type’s division, total: by zero, the dividend, so
that (x / y) * y + x % y is x whatever y is.
%
(%) : {a : Type} -> {{mod : Remainder a}} -> a -> a -> aNegation
theory Negation a where neg : a -> aA type’s negation: what -x is, the neg in scope applied to x.
neg
neg : {a : Type} -> {{n : Negation a}} -> a -> aFloatDivision
theory FloatDivision a where divide : a -> a -> aA float type’s division, IEEE’s: by 0, an infinity (or not a number,
of 0 by 0) — what /. is, the prelude’s of Float64, float32’s of
Float32. An integer type has none: its division is /, total.
/.
(/.) : {a : Type} -> {{divide : FloatDivision a}} -> a -> a -> aIsZero
theory IsZero a where isZero : a -> BoolWhether a value is its type’s zero: what exception’s divOrThrow and
modOrThrow ask of the divisor — the prelude’s of Int, a fixed-width
integer type’s module’s of its own.
Bitwise
theory Bitwise a where and : a -> a -> a or : a -> a -> a xor : a -> a -> a complement : a -> a shiftL : a -> a -> a shiftR : a -> a -> aAn integer type’s bits, as two’s complement has them: the and, or and
xor of two, every bit flipped, and shifts — an Int’s in int’s
module, a fixed-width type’s in its own.
and
and : {a : Type} -> {{bits : Bitwise a}} -> a -> a -> aThe bits set in both.
or
or : {a : Type} -> {{bits : Bitwise a}} -> a -> a -> aThe bits set in either.
xor
xor : {a : Type} -> {{bits : Bitwise a}} -> a -> a -> aThe bits set in one of the two.
complement
complement : {a : Type} -> {{bits : Bitwise a}} -> a -> aEvery bit flipped.
shiftL
shiftL : {a : Type} -> {{bits : Bitwise a}} -> a -> a -> aShifted left by the second, as the type shifts.
shiftR
shiftR : {a : Type} -> {{bits : Bitwise a}} -> a -> a -> aShifted right by the second, as the type shifts.
intAdd
intAdd : Int -> Int -> IntintSub
intSub : Int -> Int -> IntintMul
intMul : Int -> Int -> IntintDiv
intDiv : Int -> Int -> IntintMod
intMod : Int -> Int -> IntintEq
intEq : Int -> Int -> BoolintLt
intLt : Int -> Int -> BoolintLe
intLe : Int -> Int -> BoolintShow
intShow : Int -> StringinstanceEqualityInt
instance instanceEqualityInt : Equality IntcompareInt
compareInt : Int -> Int -> OrderinginstanceOrderInt
instance instanceOrderInt : Order Int>>> 1 < 2 && 2 <= 2 || FalseTrue>>> ([max 2 (-3), min 2 (-3)] : List Int)Cons 2 (Cons (-3) Nil)instanceAdditionInt
instance instanceAdditionInt : Addition IntinstanceSubtractionInt
instance instanceSubtractionInt : Subtraction IntinstanceMultiplicationInt
instance instanceMultiplicationInt : Multiplication IntinstanceDivisionInt
instance instanceDivisionInt : Division IntDivision rounding down; by 0, 0.
instanceRemainderInt
instance instanceRemainderInt : Remainder IntThe remainder of /, of the sign of the divisor; by 0, the dividend.
>>> 1 + 2 * 3 - 4 / 25>>> ([7 / 2, -7 / 2, 7 % 2, -7 % 2, 7 % -2] : List Int)Cons 3 (Cons (-4) (Cons 1 (Cons 1 (Cons (-1) Nil))))>>> ([7 / 0, 7 % 0, (7 / 0) * 0 + 7 % 0] : List Int)Cons 0 (Cons 7 (Cons 7 Nil))instanceNegationInt
instance instanceNegationInt : Negation IntThe integer of the other sign, 0 - x: what -x is.
>>> ([neg 5, -(3 - 10)] : List Int)Cons (-5) (Cons 7 Nil)instanceIsZeroInt
instance instanceIsZeroInt : IsZero Int>>> ([instanceIsZeroInt.isZero 0, instanceIsZeroInt.isZero (-3)] : List Bool)Cons True (Cons False Nil)floatAdd
floatAdd : Float64 -> Float64 -> Float64floatSub
floatSub : Float64 -> Float64 -> Float64floatMul
floatMul : Float64 -> Float64 -> Float64floatDiv
floatDiv : Float64 -> Float64 -> Float64floatEq
floatEq : Float64 -> Float64 -> BoolfloatLt
floatLt : Float64 -> Float64 -> BoolfloatLe
floatLe : Float64 -> Float64 -> BoolfloatShow
floatShow : Float64 -> StringfloatFromInt
floatFromInt : Int -> Float64floatSqrt
floatSqrt : Float64 -> Float64floatFloor
floatFloor : Float64 -> IntinstanceEqualityFloat64
instance instanceEqualityFloat64 : Equality Float64compareFloat
compareFloat : Float64 -> Float64 -> OrderinginstanceOrderFloat64
instance instanceOrderFloat64 : Order Float64instanceAdditionFloat64
instance instanceAdditionFloat64 : Addition Float64instanceSubtractionFloat64
instance instanceSubtractionFloat64 : Subtraction Float64instanceMultiplicationFloat64
instance instanceMultiplicationFloat64 : Multiplication Float64instanceNegationFloat64
instance instanceNegationFloat64 : Negation Float64The float of the other sign, 0.0’s too: what -x is.
instanceFloatDivisionFloat64
instance instanceFloatDivisionFloat64 : FloatDivision Float64Division; by 0, an infinity (or not a number, of 0 by 0): a float has
no /, whose division by 0 is 0.
>>> ([neg 2.5, -(1.0 - 3.5), 1.0 /. neg 0.0, 2.5 * 2.0 + 1.0] : List Float64)[-2.5, 2.5, -Infinity, 6.0]abs
abs : {a : Type} -> {{ord : Order a}} -> {{n : Negation a}} -> a -> ax without its sign: the greater of x and -x.
>>> abs (-3)3>>> abs 77>>> abs (-2.5)2.5toFloat
toFloat : Int -> Float64floor
floor : Float64 -> IntThe greatest integer not above; of an infinity, or what is not a number, 0.
>>> ([floor 2.5, floor (-2.5), floor (1.0 /. 0.0), floor (-1.0 /. 0.0), floor (0.0 /. 0.0)] : List Int)Cons 2 (Cons (-3) (Cons 0 (Cons 0 (Cons 0 Nil))))sqrt
sqrt : Float64 -> Float64strAppend
strAppend : String -> String -> StringstrLength
strLength : String -> IntstrSlice
strSlice : String -> Int -> Int -> StringstrEq
strEq : String -> String -> BoolstrLt
strLt : String -> String -> BoolstrCompare
strCompare : String -> String -> IntstrFind
strFind : String -> String -> Int -> Int^
(^) : String -> String -> Stringa ^ b: the string a, then b.
>>> "count: " ^ intShow (7 % 3)"count: 1">>> "he" ^ "ff" ^ "!""heff!"instanceEqualityString
instance instanceEqualityString : Equality StringbytesEq
bytesEq : Bytes -> Bytes -> BoolbytesLength
bytesLength : Bytes -> IntbytesSlice
bytesSlice : Bytes -> Int -> Int -> BytesbytesConcat
bytesConcat : List Bytes -> BytesbytesIntAt
bytesIntAt : Bytes -> Int -> Int -> Int -> IntbytesOfInt
bytesOfInt : Int -> Int -> Int -> BytesbytesHasAt
bytesHasAt : Bytes -> Int -> Bytes -> BoolbytesSized
bytesSized : Int -> Bytes -> BytesThe first n bytes of b, as a segment x::binary-size(n) of a
binary writes them: of fewer, abandoned.
instanceEqualityBytes
instance instanceEqualityBytes : Equality BytesBytes’ (their other operations are bytes’s): the same bytes.
>>> b["hi", 255] == b[104, "i", 0xFF]TrueinstanceEqualityRune
instance instanceEqualityRune : Equality RuneinstanceEqualityBool
instance instanceEqualityBool : Equality BoolinstanceEqualityUnit
instance instanceEqualityUnit : Equality UnitinstanceEqualityOrdering
instance instanceEqualityOrdering : Equality Orderingequal
equal : {a : Type} -> {{eq : Equality a}} -> a -> a -> BoolWhether the two are equal, as the instance of their type says.
>>> equal 3 3True>>> equal "heff" "help"False>>> equal 0.5 0.5 && not (equal 'a' 'b') && equal (1 < 2) TrueTrue>>> equal (compareInt 1 2) LTTrueinstanceEqualityList
instance instanceEqualityList : {a : Type} -> {{eq : Equality a}} -> Equality (List a)Lists are equal where they are as long, and equal element by element.
>>> equal ([1, 2] : List Int) [1, 2]True>>> equal ([[1, 2], [3]] : List (List Int)) [[1, 2], []]FalseinstanceEqualityMaybe
instance instanceEqualityMaybe : {a : Type} -> {{eq : Equality a}} -> Equality (Maybe a)>>> equal (Just 'h' : Maybe Rune) (Just 'h')True>>> equal (Just [1] : Maybe (List Int)) NothingFalseinstanceEqualityPair
instance instanceEqualityPair : {a b : Type} -> {{eqA : Equality a}} -> {{eqB : Equality b}} -> Equality (a, b)>>> equal (MkPair 1 "one" : Pair Int String) (MkPair 1 "one")TrueinstanceEqualityEither
instance instanceEqualityEither : {a b : Type} -> {{eqA : Equality a}} -> {{eqB : Equality b}} -> Equality (Either a b)>>> equal (Left 1 : Either Int String) (Right "1")Falsefst
fst : {a b : Type} -> (a, b) -> asnd
snd : {a b : Type} -> (a, b) -> bmaybe
maybe : {a b : Type} -> b -> (a -> b) -> Maybe a -> bfromMaybe
fromMaybe : {a : Type} -> a -> Maybe a -> a>>> fromMaybe 0 (Just 4)4either
either : {a b c : Type} -> (a -> c) -> (b -> c) -> Either a b -> cMonad
theory Monad (m : Type -> Type) where pure : {a : Type} -> a -> m a bind : {a b : Type} -> m a -> (a -> m b) -> m bA monad, no laws asked: a value as a computation (pure), and a
computation and what comes after it as one (bind). do is not
this: it takes the bind in scope by name, so a monad’s module keeps
its own bind and pure, and builds its instance of them — the
prelude’s of Maybe and Either e, co’s of Co h, generator’s
of Generator. What is written once for every monad asks for one,
{{mo : Monad m}}, and a module using it at its own monad gives its
instance once: traverseS = traverse (mo := instanceMonadS).
>>=
(>>=) : {m : Type -> Type} -> {{mo : Monad m}} -> {a b : Type} -> m a -> (a -> m b) -> m bA monad’s bind, written between: c >>= f is f of what c
gives, as do writes x <- c then f x.
instanceMonadMaybe
instance instanceMonadMaybe : Monad MaybeMaybe’s monad: a computation that may give nothing, and then the
rest gives nothing too.
instanceMonadEither
instance instanceMonadEither : {e : Type} -> Monad (Either e)Either e’s monad: a computation that may fail with an e
(Left), and then the rest fails with it too.
traverse
traverse : {m : Type -> Type} -> {{mo : Monad m}} -> {a b : Type} -> (a -> m b) -> List a -> m (List b)f of each element, in order, and the list of what they gave.
>>> traverse (mo := instanceMonadMaybe) (\x -> if x > 0 then Just (x * 2) else Nothing) [1, 2, 3]Just [2, 4, 6]>>> traverse (mo := instanceMonadMaybe) (\x -> if x > 0 then Just x else Nothing) [1, -2, 3]NothingfoldM
foldM : {m : Type -> Type} -> {{mo : Monad m}} -> {a b : Type} -> (b -> a -> m b) -> b -> List a -> m bA left fold, each step a computation: f z x1, then f of what it
gave and x2, and so on.
>>> foldM (mo := instanceMonadMaybe) (\acc x -> if x > 0 then Just (acc + x) else Nothing) 0 [1, 2, 3]Just 6when
when : {m : Type -> Type} -> {{mo : Monad m}} -> Bool -> m Unit -> m Unitc if b, else nothing done.
>>> when (mo := instanceMonadMaybe) False NothingJust MkUnitunless
unless : {m : Type -> Type} -> {{mo : Monad m}} -> Bool -> m Unit -> m Unitc unless b: if b, nothing done.
>>> unless (mo := instanceMonadMaybe) False NothingNothingreplicateM
replicateM : {m : Type -> Type} -> {{mo : Monad m}} -> {a : Type} -> Int -> m a -> m (List a)c, n times (none, for n not above 0), and the list of what it
gave each time.
>>> replicateM (mo := instanceMonadEither) 3 (Right 'x' : Either String Rune)Right ['x', 'x', 'x']Id
type Id a = aThe identity monad: a value is its own computation. Pure code
written as statements is run do ..., whose do is taken apart by
this monad’s idBind and idPure: their calls simplified away, each
of its loops a function calling only itself, giving its variables back.
run
run : {a : Type} -> Id a -> athe value of a computation of the identity monad: run do ...
idPure
idPure : {a : Type} -> a -> Id aidBind
idBind : {a b : Type} -> Id a -> (a -> Id b) -> Id btypeOf
typeOf : {a : Type} -> a -> Typethe type of x: what a do block’s loop takes its variable x as,
and what x := e checks e against
inferred
inferred : {a : Type} -> Unit -> Typea type its uses decide, the implicit argument left to be solved:
what a do block’s loop gives, and what let mut x = e checks e
against
leaveScope
leaveScope : {a : Type} -> (Unit -> a) -> aWhat a scope’s answer says to do once it is left, done: a do
block’s try and with go on so, to what follows them or further
out.
++
(++) : {a : Type} -> List a -> List a -> List axs ++ ys: the elements of xs, then those of ys.
>>> [1, 2] ++ [3]Cons 1 (Cons 2 (Cons 3 Nil))Iterate
theory Iterate c where Elem : Type Cursor : Type start : c -> Cursor next : Cursor -> Maybe (Elem, Cursor)What for x in c do ... goes through: a cursor over c’s elements
(each an Elem), from where it starts, each step the next element
and the cursor after it, or nothing at the end. A list’s cursor is
the list, an array’s its index, a range’s what is left of it.
iterateOf
iterateOf : {c : Type} -> {{it : Iterate c}} -> c -> Iterate cthe instance of Iterate found for x’s type: what a for over
x goes through it by
instanceIterateList
instance instanceIterateList : {a : Type} -> Iterate (List a)A list, from its first element.
Range
data Range = MkRange Int IntThe integers from one to another, both of them in, as for goes
through them (none, if the second is less than the first).
range
range : Int -> Int -> RangeinstanceIterateRange
instance instanceIterateRange : Iterate RangeA range, from its first integer up.
strByteAt
strByteAt : String -> Int -> IntstrFromByte
strFromByte : UInt8 -> StringbyteAt
byteAt : String -> Int -> IntThe byte at i, 0 to 255; out of range, -1.
>>> byteAt "a\u{e9}" 1195>>> byteAt "a\u{e9}" 3-1fromByte
fromByte : UInt8 -> StringThe string of one byte: a byte of no rune too, which no literal but
a \xNN escape has. An Int is made a byte by uint8’s fromInt,
wrapping around (fromByte (U8.fromInt n)).
>>> fromByte 104 ^ fromByte 105"hi">>> fromByte 255 == "\xff" && byteAt (fromByte 0) 0 == 0TruestrRunes
strRunes : String -> List RunestrOfRunes
strOfRunes : List Rune -> StringstrRuneAt
strRuneAt : String -> Int -> RunestrRuneWidth
strRuneWidth : String -> Int -> IntruneToInt
runeToInt : Rune -> Intuint8FromInt
uint8FromInt : Int -> UInt8runes
runes : String -> List RuneThe runes of s, its code points, UTF-8 read: runes "a😀" is
['a', '😀']; what is not UTF-8 is U+FFFD, one for each longest
start of a rune’s bytes (or a byte that starts none), as
TextDecoder reads it. Their operations are rune’s.
fromRunes
fromRunes : List Rune -> StringThe string of runes, UTF-8 (one that is no Unicode scalar value,
U+FFFD): fromRunes (runes s) is s, where s is UTF-8.
RuneAt
type RuneAt = { rune : Rune, width : Int }A rune of a string, and how many bytes of it it takes.
runeAt
runeAt : String -> Int -> RuneAtThe rune whose bytes start at i, and how many they are (Go’s
utf8.DecodeRuneInString): where they are not UTF-8, U+FFFD, as
runes reads it; out of range, U+FFFD of none.
>>> (runeAt "a\u{e9}b" 1).width2>>> (runeAt "a\u{e9}b" 2).width1instanceIterateString
instance instanceIterateString : Iterate StringA string, rune by rune, as runes reads it: its cursor is the
string and the byte its next rune starts at.
compareString
compareString : String -> String -> OrderingThe order of two strings, their bytes’ (of UTF-8, their runes’), by one comparison of them.
>>> (MkPair (compareString "pear" "apple") (compareString "pear" "pears") : Pair Ordering Ordering)MkPair GT LT>>> compareString "z" "\u{e9}"LTorderByCompare
orderByCompare : {a : Type} -> {{eq : Equality a}} -> (a -> a -> Ordering) -> Order aThe Order of a comparison and the type’s equality: lt and le
are by the comparison.
instanceOrderString
instance instanceOrderString : Order StringStrings’ order, their bytes’ (compareString’s).
>>> "apple" < "pear" && not ("pear" <= "pea")TrueinstanceOrderBool
instance instanceOrderBool : Order BoolFalse before True.
>>> compare (False : Bool) TrueLTinstanceOrderUnit
instance instanceOrderUnit : Order UnitinstanceOrderOrdering
instance instanceOrderOrdering : Order OrderingLT before EQ before GT.
instanceOrderList
instance instanceOrderList : {a : Type} -> {{ord : Order a}} -> Order (List a)Lists by their elements, the first that differ (a list before a longer one it begins).
>>> (MkPair (compare ([1, 2] : List Int) [1, 3]) (compare ([1, 2] : List Int) [1]) : Pair Ordering Ordering)MkPair LT GT>>> (instanceOrderList : Order (List Int)).eq.equal [1, 2] [1, 2]TrueinstanceOrderMaybe
instance instanceOrderMaybe : {a : Type} -> {{ord : Order a}} -> Order (Maybe a)Nothing before any Just, and those by what they hold.
instanceOrderPair
instance instanceOrderPair : {a b : Type} -> {{ordA : Order a}} -> {{ordB : Order b}} -> Order (a, b)Pairs by their first, then their second.
>>> compare (MkPair 1 "b" : Pair Int String) (MkPair 1 "a")GTindexOf
indexOf : String -> String -> (from : Int) -> Maybe IntWhere needle is first in s, from byte from on (from 0, a
from below it), if it is.
>>> indexOf "lo" "hello, world: lo" 0Just 3>>> indexOf "lo" "hello, world: lo" 4Just 14>>> indexOf "," "a,b,c" (from := 2)Just 3>>> indexOf "" "ab" 2Just 2>>> indexOf "" "ab" 3Nothingcontains
contains : String -> String -> Bool>>> contains "ell" "hello" && not (contains "elo" "hello")TruestartsWith
startsWith : (prefix : String) -> String -> BoolendsWith
endsWith : String -> String -> Boolsplit
split : String -> String -> List StringThe pieces of s between the seps (not empty: split "," "a,,b" is
["a", "", "b"]).
>>> split ", " "a, b, , c"Cons "a" (Cons "b" (Cons "" (Cons "c" Nil)))joinWith
joinWith : String -> List String -> StringThe strings, with sep between each two.
lines
lines : String -> List StringThe pieces of s between its line breaks ("\n").
>>> lines "one\ntwo\n"Cons "one" (Cons "two" (Cons "" Nil))unlines
unlines : List String -> StringisSpaceCode
isSpaceCode : Int -> Boolwords
words : String -> List StringThe pieces of s between its spaces, tabs and line breaks.
unwords
unwords : List String -> StringskipSpaces
skipSpaces : String -> Int -> Int -> Inttrim
trim : String -> StringWithout the spaces at either end.
parseInt
parseInt : String -> Maybe IntA decimal integer (42, -7), if s is one, whole.
foldBytes
foldBytes : {a : Type} -> (a -> Int -> a) -> a -> String -> aThe bytes, each 0 to 255, from the first, into z; no list of them
made, as runes would make one (rune’s foldl goes through the
runes so).
>>> foldBytes (\n b -> n * 2 + b % 2) 0 "ab\xff"5byteString
byteString : Int -> StringmapBytes
mapBytes : (Int -> Int) -> String -> StringEach byte f of it, given 0 to 255 (and what it gives wrapped
around to that, as uint8’s fromInt wraps): as long a string, no
list of its bytes made, but the string itself grown, in place, as
^ grows one.
>>> mapBytes (\b -> if 97 <= b && b <= 122 then b - 32 else b) "heff, \u{e9}!""HEFF, \u{e9}!">>> mapBytes (\b -> b + 1) "\xff\x00a""\x00\x01b"withCodePoint
withCodePoint : String -> Int -> StringmapRunes
mapRunes : (Rune -> Rune) -> String -> StringEach rune f of it, the runes read as runes reads them (what is
not UTF-8, U+FFFD) and written as fromRunes writes them:
fromRunes (List.map f (runes s)), but no list made, the string grown,
in place, as ^ grows one.
>>> mapRunes (\c -> if c == 'a' then '\u{3bb}' else c) "a\xffb\u{e9}""\u{3bb}\u{FFFD}b\u{e9}">>> mapRunes (\c -> c) "\xe9\x80" == fromRunes (runes "\xe9\x80")TruefloatOfDecimal
floatOfDecimal : Int -> String -> Int -> Int -> Float64The float, of 64 bits or 32 (n), nearest the decimal strSlice s i j — a -, digits, perhaps a point and digits, perhaps an
exponent (2.5, -1e-7, 12.5E+3), nothing else — rounded once, a
tie to the even, as std.math’s fromDecimal and float32’s round m
times 10 to the power e; of text that is no such decimal, NaN, as
no decimal is. parseFloat and float32’s parseFloat32 read a
whole string so.
parseFloat
parseFloat : String -> Maybe Float64The float nearest the decimal s is, whole (2.5, -1e-7), as
floatOfDecimal reads one, if it is one: correctly rounded, as a
float literal is.
>>> parseFloat "0.1"Just 0.1>>> parseFloat "-0"Just (-0.0)>>> parseFloat "2.4703282292062328e-324"Just 5.0e-324>>> parseFloat "1e400"Just Infinity>>> parseFloat "1."NothingDebug
theory Debug a where debug : a -> StringA type’s values as the source writes them — a string quoted, debug "hi" is "\"hi\"", a rune debug 'a' is "'a'", bytes a literal —
so that two values that differ are not written the same: what a test
shows a value as and compares two by (check’s assertEqual,
forAll), as Rust’s Debug and Python’s repr are. The prelude’s
instances are of Int, Float64, String, Rune, Bytes, Bool,
Unit and Ordering, and of a List, a Maybe, a Pair and an
Either of types that have one; a fixed-width type’s is its
module’s.
debug
debug : {a : Type} -> {{shows : Debug a}} -> a -> StringThe value written as its type’s instance writes it.
showInt
showInt : Int -> StringAn Int as a literal writes it, Int’s debug.
>>> showInt 42 ^ " " ^ showInt (-7)"42 -7"showFloat
showFloat : Float64 -> StringA Float64 as a literal writes it, Float64’s debug: the fewest
digits that read back as it, a point among them, an exponent beyond
1e21 and below 1e-6, and -0.0 with its sign — read as a literal, the
very float. What no literal is, as it is: NaN, Infinity,
-Infinity.
>>> showFloat 2.5"2.5">>> showFloat (neg 0.0) ^ " " ^ showFloat 1.0e23 ^ " " ^ showFloat 5.0e-324"-0.0 1.0e23 5.0e-324">>> showFloat 100.0 ^ " " ^ showFloat 1.0e-7"100.0 1.0e-7"instanceDebugInt
instance instanceDebugInt : Debug IntinstanceDebugFloat64
instance instanceDebugFloat64 : Debug Float64>>> debug 42 ^ " " ^ debug (-7) ^ " " ^ debug 2.5"42 -7 2.5"instanceDebugString
instance instanceDebugString : Debug StringQuoted, its ", \ and line feeds escaped.
>>> debug "say \"hi\"\n""\"say \\\"hi\\\"\\n\"">>> debug "hi""\"hi\""instanceOrderRune
instance instanceOrderRune : Order RuneRunes by their code points.
>>> 'a' < 'b' && compare 'z' 'a' == GTTrueinstanceDebugRune
instance instanceDebugRune : Debug RuneA rune as a literal writes it, quoted: a control character an
escape, one that is no scalar value as U+FFFD (as Go’s %q).
>>> debug 'a' ^ " " ^ debug '\'' ^ " " ^ debug '\n' ^ " " ^ debug '\u{1b}'"'a' '\\'' '\\n' '\\u{1b}'"bytesToList
bytesToList : Bytes -> List UInt8uint8ToInt
uint8ToInt : UInt8 -> IntinstanceDebugBytes
instance instanceDebugBytes : Debug BytesBytes as a binary writes them, b[...]: each run of printable
ASCII, a byte from 32 up to 126, a string (" and \ escaped), and
any other byte its number.
>>> debug b[10, "GET \"\\", 195, 169]"b[10, \"GET \\\"\\\\\", 195, 169]">>> debug b[]"b[]"instanceDebugBool
instance instanceDebugBool : Debug BoolinstanceDebugUnit
instance instanceDebugUnit : Debug UnitinstanceDebugOrdering
instance instanceDebugOrdering : Debug Ordering>>> debug (True : Bool) ^ " " ^ debug (MkUnit : Unit) ^ " " ^ debug (GT : Ordering)"True MkUnit GT"instanceDebugList
instance instanceDebugList : {a : Type} -> {{shows : Debug a}} -> Debug (List a)>>> debug ([1, 2] : List Int)"[1, 2]">>> debug ([["a"], []] : List (List String))"[[\"a\"], []]"instanceDebugMaybe
instance instanceDebugMaybe : {a : Type} -> {{shows : Debug a}} -> Debug (Maybe a)>>> debug (Just [1] : Maybe (List Int)) ^ " " ^ debug (Nothing : Maybe Int)"Just ([1]) Nothing"instanceDebugPair
instance instanceDebugPair : {a b : Type} -> {{showsA : Debug a}} -> {{showsB : Debug b}} -> Debug (a, b)>>> debug (MkPair 1 "one" : Pair Int String)"MkPair (1) (\"one\")"instanceDebugEither
instance instanceDebugEither : {a b : Type} -> {{showsA : Debug a}} -> {{showsB : Debug b}} -> Debug (Either a b)>>> debug (Left 1 : Either Int String) ^ " " ^ debug (Right "1" : Either Int String)"Left (1) Right (\"1\")"Show
theory Show a where show : a -> StringA type’s values as text, for a reader rather than for the source —
a string itself, a rune its one-rune string, bytes the text they are
— as Rust’s Display and Python’s str are, beside Debug (Rust’s
Debug, Python’s repr). The prelude’s instances are of String, Rune
and Bytes, and of Int, Float64, Bool, Unit and Ordering,
written as debug writes them; a fixed-width type’s is its module’s,
as debug writes it too. A List, a Maybe, a Pair and an
Either have none: there is no one text of them.
show
show : {a : Type} -> {{text : Show a}} -> a -> StringThe value as its type’s instance makes it text.
instanceShowString
instance instanceShowString : Show StringItself.
>>> show "hi""hi"instanceShowRune
instance instanceShowRune : Show RuneThe string of it alone, fromRunes [c] (Go’s string(c)).
>>> show 'a'"a"bytesToString
bytesToString : Bytes -> StringinstanceShowBytes
instance instanceShowBytes : Show BytesThe text of them, UTF-8, what is not UTF-8 U+FFFD, as rune’s
toValid makes it (and TextDecoder reads it).
>>> show b["h", 0xc3, 0xa9, 0xff, "i"]"hé\u{FFFD}i"instanceShowInt
instance instanceShowInt : Show IntinstanceShowFloat64
instance instanceShowFloat64 : Show Float64>>> show 42 ^ " " ^ show (-7) ^ " " ^ show 2.5"42 -7 2.5"instanceShowBool
instance instanceShowBool : Show BoolinstanceShowUnit
instance instanceShowUnit : Show UnitinstanceShowOrdering
instance instanceShowOrdering : Show Ordering>>> show (True : Bool) ^ " " ^ show (MkUnit : Unit) ^ " " ^ show (GT : Ordering)"True MkUnit GT"onWindows
onWindows : Unit -> BoolWhether the program runs on Windows: as the system it is built for
says — a C program, the target zig builds it for; in JavaScript,
Node.js’s process.platform (False in a page). The same all
through a run, so a function of no effect; std.path reads a path in
the style it says.
Coe
theory Coe from to where coe : from -> toA value of one type taken as one of another, without saying so:
where an expression of type from is given and a to is expected,
and the two do not unify, heff puts in coe, by the one instance
of Coe from to in scope (as any instance argument is found). Both
types must be known whole there; one coercion is put in, never two
in a row. The prelude has one, instanceCoeLazy: a module that has
a type made from another declares its own, as std.path does
Coe String Path.
coe
coe : {from to : Type} -> {{coerces : Coe from to}} -> from -> toThe value taken as a to, as its instance takes it: what heff puts
in where a coercion is wanted.
instanceCoeLazy
instance instanceCoeLazy : {a : Type} -> Coe ~a aA Lazy a, ~a, where an a is expected: forced.
bitsEq
bitsEq : Bits -> Bits -> BoolbitsLength
bitsLength : Bits -> IntbitsIntAt
bitsIntAt : Bits -> Int -> Int -> Int -> IntbitsOfInt
bitsOfInt : Int -> Int -> Int -> BitsbitsConcat
bitsConcat : List Bits -> BitsbitsSlice
bitsSlice : Bits -> Int -> Int -> BitsbitsOfBytes
bitsOfBytes : Bytes -> BitsbitsBytes
bitsBytes : Bits -> BytesfloatBits
floatBits : Int -> Float64 -> IntfloatOfBits
floatOfBits : Int -> Int -> Float64runeFromInt
runeFromInt : Int -> RunebitsSized
bitsSized : Int -> Bits -> BitsThe first n bits of b, as a segment x::bits-size(n) writes
them: of fewer, abandoned.
bitsHasBytesAt
bitsHasBytesAt : Bits -> Int -> Bytes -> BoolWhether the bytes s are those of b at bit o.
>>> bitsHasBytesAt (bitsConcat [bitsOfInt 4 0 1, bitsOfBytes b["hi"]]) 4 b["hi"]TrueCodePoint
theory CodePoint a where codePoint : a -> IntWhat a segment of utf8, utf16 or utf32 writes: a code point,
an Int’s or a Rune’s.
instanceCodePointInt
instance instanceCodePointInt : CodePoint IntinstanceCodePointRune
instance instanceCodePointRune : CodePoint RunecodePointOf
codePointOf : {a : Type} -> {{point : CodePoint a}} -> a -> IntThe code point of a value of CodePoint.
isScalarValue
isScalarValue : Int -> BoolWhether c is a Unicode scalar value: from 0 up to U+10FFFF, but
the surrogates.
utf8Bytes
utf8Bytes : Int -> BytesThe code point c as UTF-8, as a segment c::utf8 writes it: what
is no scalar value, abandoned.
>>> bytesToList (bytesConcat [utf8Bytes 65, utf8Bytes 233, utf8Bytes 8364, utf8Bytes 128512])[65, 195, 169, 226, 130, 172, 240, 159, 152, 128]utf16Bytes
utf16Bytes : Int -> Int -> BytesThe code point c as UTF-16, as a segment c::utf16 writes it,
its units as the flags f say (1 little-endian): what is no scalar
value, abandoned.
utf32Bytes
utf32Bytes : Int -> Int -> BytesThe code point c as UTF-32: what is no scalar value, abandoned.
utf8Count
utf8Count : Int -> Intutf8Lead
utf8Lead : Int -> Intutf8Least
utf8Least : Int -> Intutf8Rest
utf8Rest : (Int -> Int) -> Int -> Int -> Int -> Intutf8CodeBy
utf8CodeBy : (Int -> Int) -> Int -> Intutf8WidthOf
utf8WidthOf : Int -> Int -> Intutf8WidthBy
utf8WidthBy : (Int -> Int) -> IntbytesByteAt
bytesByteAt : Bytes -> Int -> Int -> IntbitsByteAt
bitsByteAt : Bits -> Int -> Int -> IntbytesUtf8Width
bytesUtf8Width : Bytes -> Int -> IntHow many bits the UTF-8 code point at bit o of b is, as a
segment c::utf8 reads it: where there is none (a byte that is no
continuation, too few, a surrogate, one written longer than it is),
0.
>>> ([bytesUtf8Width b["a", 0xc3, 0xa9] 0, bytesUtf8Width b["a", 0xc3, 0xa9] 8, bytesUtf8Width b[0xc3, 0x28] 0, bytesUtf8Width b[0xed, 0xa0, 0x80] 0, bytesUtf8Width b[0xc0, 0x80] 0, bytesUtf8Width b[0xc3] 0] : List Int)[8, 16, 0, 0, 0, 0]bitsUtf8Width
bitsUtf8Width : Bits -> Int -> IntbytesUtf8At
bytesUtf8At : Bytes -> Int -> RuneThe UTF-8 code point at bit o of b, there.
bitsUtf8At
bitsUtf8At : Bits -> Int -> Runeutf16WidthBy
utf16WidthBy : (Int -> Int) -> Intutf16CodeBy
utf16CodeBy : (Int -> Int) -> IntbytesUnitAt
bytesUnitAt : Bytes -> Int -> Int -> Int -> IntbitsUnitAt
bitsUnitAt : Bits -> Int -> Int -> Int -> IntbytesUtf16Width
bytesUtf16Width : Bytes -> Int -> Int -> IntHow many bits the UTF-16 code point at bit o of b is, its units
as the flags f say: where there is none, 0.
bitsUtf16Width
bitsUtf16Width : Bits -> Int -> Int -> IntbytesUtf16At
bytesUtf16At : Bytes -> Int -> Int -> RuneThe UTF-16 code point at bit o of b, there.
bitsUtf16At
bitsUtf16At : Bits -> Int -> Int -> RuneinstanceEqualityBits
instance instanceEqualityBits : Equality BitsBits’ (their other operations are bits’s): the same bits.
>>> bitsOfInt 3 0 5 == bitsConcat [bitsOfInt 1 0 1, bitsOfInt 2 0 1]True>>> bitsOfBytes b[1, 2] == bitsOfInt 16 0 258TrueinstanceDebugBits
instance instanceDebugBits : Debug BitsBits as a binary writes them: their whole bytes as bytes are
(instanceDebugBytes), then the bits left, v::k — or, none left,
b[]::bits, so that what is written is Bits again.
>>> debug (bitsConcat [bitsOfBytes b["GET"], bitsOfInt 3 0 5])"b[\"GET\", 5::3]">>> debug (bitsOfBytes b[1, 2]) ^ " " ^ debug (bitsOfBytes b[]) ^ " " ^ debug (bitsOfInt 1 0 1)"b[1, 2, b[]::bits] b[b[]::bits] b[1::1]"instanceShowBits
instance instanceShowBits : Show BitsTheir bits, each 0 or 1.
>>> show (bitsOfInt 5 0 21)"10101"natrec
natrec : {c : Type} -> c -> (Nat -> c -> c) -> Nat -> cRecursion on Nat, non-dependent.
>>> natrec (c := Nat) Zero (\_ n -> Succ (Succ n)) (Succ (Succ Zero))Succ (Succ (Succ (Succ Zero)))