APIBasics

Basics

The standard classes, operators, and arithmetic helpers.

The prelude exposes the classes, Type, the operators, show, display, and ignore. The other methods are reached qualified, as in Basics.negate, and the integer helpers modBy, remainderBy, and quotientBy need import Basics exposing (modBy, quotientBy, remainderBy).

The standard classes are independent of each other: in particular, Ord does not imply Eq.

Type

type Type aSource

A runtime witness of a type argument, which directs a call whose result type nothing else determines, as Json.parse @Person text does. The witness expression @T is its only public constructor.

Display

class Display aSource

Text for output. It differs from the representation only where a type deliberately renders as itself, as String and Char do; everything else displays its representation.

display "a" == "a"
display 'x' == "x"
display (Just "a") == "Just \"a\""

Methods

displayTo

displayTo : Display a => Builder -> a -> BuilderSource

Appends a value’s output text to an immutable builder. String interpolation uses this method, so it should agree with display.

display

display : Display a => a -> StringSource

The text of a value for output. Defaults to rendering into an empty builder and returning its text.

Instances:

Display ()
Display Bool
Display Char
Display Float
Display Int
Display String
Show a => Display a

Eq

class Eq aSource

Equality. Every standard scalar type has it, and derived instances compare constructors and then their fields, left to right.

Methods

(==)

(==) : Eq a => a -> a -> BoolSource

Whether two values are equal.

infix 4

Instances:

(Eq a, Eq b) => Eq (Dict a b)
(Eq a, Eq b) => Eq (Result a b)
(Eq a, Eq b) => Eq (a, b)
(Eq a, Eq b, Eq c) => Eq (a, b, c)
(Eq b, Eq a) => Eq (Parsed a b)
Eq ()
Eq Authority
Eq Bool
Eq Bytes
Eq CaseOutcome
Eq Char
Eq Component
Eq Console.Output
Eq Date
Eq DateTime
Eq Duration
Eq Encoding.Error
Eq Event
Eq Expect.Error
Eq Fault
Eq Float
Eq Frame
Eq Framing
Eq Header
Eq Http.Client.Error
Eq Http.Error
Eq IO.Error
Eq IO.Kind
Eq Instant
Eq Int
Eq Json.Pull.Error
Eq Line
Eq Match
Eq Mode
Eq Net.Endpoint
Eq Net.Error
Eq Net.Kind
Eq Param
Eq Period
Eq Reader.Read
Eq Regex.Capture
Eq Regex.Error
Eq Reply
Eq Resolution
Eq Security
Eq Span
Eq Status
Eq String
Eq Summary
Eq Text.Reader.Read
Eq Time.Error
Eq TimeOfDay
Eq Token
Eq Url
Eq Verdict
Eq Version
Eq Weekday
Eq Zone
Eq a => Eq (List a)
Eq a => Eq (Maybe a)
Eq a => Eq (Outcome a)
Eq a => Eq (Parser.Error a)
Eq a => Eq (Reason a)

Num

class Num aSource

Numbers: Int and Float. An integer literal is a number of any Num type, defaulting to Int when nothing else decides; a decimal literal is a Float.

1 + 2 * 3 == 7
7 - 10 == -3
1.5 * 2.0 == 3.0

Methods

fromInt

fromInt : Num a => Int -> aSource

The number equal to an Int.

(+)

(+) : Num a => a -> a -> aSource

Addition.

infixl 6

(-)

(-) : Num a => a -> a -> aSource

Subtraction.

infixl 6

(*)

(*) : Num a => a -> a -> aSource

Multiplication.

infixl 7

negate

negate : Num a => a -> aSource

The number with the opposite sign.

Instances:

Num Float
Num Int

Ord

class Ord aSource

Ordering. Int, Float, String, and Char have it; derived instances order by constructor, in declaration order, and then by fields, left to right. Strings order by Unicode scalar values.

2 < 3
"apple" < "banana"
'a' <= 'a'

Methods

(<)

(<) : Ord a => a -> a -> BoolSource

Whether the first value is less than the second.

infix 4

(>)

(>) : Ord a => a -> a -> BoolSource

Whether the first value is greater than the second.

infix 4

(<=)

(<=) : Ord a => a -> a -> BoolSource

Whether the first value is less than or equal to the second.

infix 4

(>=)

(>=) : Ord a => a -> a -> BoolSource

Whether the first value is greater than or equal to the second.

infix 4

Instances:

(Ord a, Ord b) => Ord (Result a b)
(Ord a, Ord b) => Ord (a, b)
(Ord a, Ord b, Ord c) => Ord (a, b, c)
Ord Bytes
Ord Char
Ord Date
Ord DateTime
Ord Duration
Ord Float
Ord Instant
Ord Int
Ord String
Ord TimeOfDay
Ord Weekday
Ord a => Ord (List a)
Ord a => Ord (Maybe a)

Show

class Show aSource

A value’s representation: source-like text that reads back as the value, so strings are quoted. showArg is the representation in constructor- argument position, parenthesized where juxtaposition would misread it.

show "a" == "\"a\""
show (Just 3) == "Just 3"
Basics.showArg (Just 3) == "(Just 3)"

Methods

showTo

showTo : Show a => Builder -> a -> BuilderSource

Appends a value’s representation. Overrides of show must agree with this method, which nested values and interpolation use.

showArgTo

showArgTo : Show a => Builder -> a -> BuilderSource

Appends a representation in constructor-argument position. Defaults to showTo; override it when the representation needs parentheses.

show

show : Show a => a -> StringSource

The representation of a value. Defaults to showTo with an empty builder; an override can return a String directly to avoid allocations.

showArg

showArg : Show a => a -> StringSource

The representation in constructor-argument position. Defaults to showArgTo with an empty builder; an override must agree with it.

Instances:

(Show a, Show b) => Show (Dict a b)
(Show a, Show b) => Show (Parsed a b)
(Show a, Show b) => Show (Result a b)
(Show a, Show b) => Show (StateResult a b)
(Show a, Show b) => Show (a, b)
(Show a, Show b, Show c) => Show (a, b, c)
Show ()
Show Bool
Show Bytes
Show CaseOutcome
Show Char
Show Component
Show Console.Output
Show Date
Show DateTime
Show Duration
Show Encoding.Error
Show Event
Show Expect.Error
Show Failure
Show Fault
Show Float
Show Frame
Show Header
Show Http.Client.Error
Show Http.Error
Show IO.Error
Show IO.Kind
Show Instant
Show Int
Show Json.Pull.Error
Show Line
Show Match
Show Net.Endpoint
Show Net.Error
Show Net.Kind
Show Param
Show Period
Show Reader.Read
Show Regex.Capture
Show Regex.Error
Show Reply
Show Resolution
Show Security
Show Span
Show String
Show Summary
Show Text.Reader.Read
Show Time.Error
Show TimeOfDay
Show Token
Show Url
Show Verdict
Show Version
Show Weekday
Show Zone
Show a => Show (Diagnostic a)
Show a => Show (List a)
Show a => Show (Maybe a)
Show a => Show (Outcome a)
Show a => Show (Parser.Error a)
Show a => Show (Reason a)
Show a => Show (Report a)

(/)

(/) : Float -> Float -> FloatSource

Floating-point division. Integers divide with quotientBy.

7.0 / 2.0 == 3.5
infixl 7

(/=)

(/=) : Eq a => a -> a -> BoolSource

Whether two values differ: the negation of (==).

1 /= 2
infix 4

(++)

(++) : String -> String -> StringSource

Joins two strings.

"ab" ++ "cd" == "abcd"
infixr 5

(<|)

(<|) : (a ->{e} b) -> a ->{e} bSource

Applies a function to a value: f <| x is f x. It binds loosest and associates right, which saves parentheses around a last argument. fn’s effects are the call’s.

(List.length <| List.range 1 4) == 4
infixr 0

(|>)

(|>) : a -> (a ->{e} b) ->{e} bSource

Passes a value to a function: x |> f is f x. It binds loosest and associates left, so a pipeline reads in the order it runs. fn’s effects are the call’s.

([1, 2, 3] |> List.map { n -> n * 2 } |> List.length) == 3
infixl 0

ignore

ignore : a -> ()Source

Discard an answer. A call stands as a statement only where its type is Unit; a block discards with _ = f x, and ignore (f x) says the same in expression position. The argument is evaluated before the call, as every argument is.

ignore 42 == ()

modBy

modBy : Int -> Int -> IntSource

x modulo modulus, floored: the result has the modulus’s sign. A zero modulus crashes the program.

import Basics exposing (modBy, quotientBy, remainderBy)

modBy 3 (-4) == 2
modBy (-3) 4 == -2

quotientBy

quotientBy : Int -> Int -> IntSource

x divided by divisor, rounded toward zero, so quotientBy d x * d + remainderBy d x is x. A zero divisor crashes the program.

import Basics exposing (modBy, quotientBy, remainderBy)

quotientBy 3 7 == 2
quotientBy 3 (-7) == -2

remainderBy

remainderBy : Int -> Int -> IntSource

The remainder of dividing x by divisor, truncated: it has the dividend’s sign and pairs with quotientBy. A zero divisor crashes the program.

import Basics exposing (modBy, quotientBy, remainderBy)

remainderBy 3 7 == 1
remainderBy 3 (-4) == -1