@@ -1,7 +1,7 @@
2−module Prelude where
2+module Basics where
4−import Native.Prelude as N
4+import Native.Basics as Native
6-- Convert radians to standard Elm angles (radians).
6-- Convert radians to standard Elm angles (radians).
7radians : Float -> Float
7radians : Float -> Float
@@ -9,52 +9,72 @@ radians t = t
10-- Convert degrees to standard Elm angles (radians).
10-- Convert degrees to standard Elm angles (radians).
11degrees : Float -> Float
11degrees : Float -> Float
12−degrees d = d * Math.PI / 180
12+degrees d = d * Native.pi / 180
14-- Convert turns to standard Elm angles (radians).
14-- Convert turns to standard Elm angles (radians).
15-- One turn is equal to 360°.
15-- One turn is equal to 360°.
16turns : Float -> Float
16turns : Float -> Float
17−turns r = 2 * Math.PI * r
17+turns r = 2 * Native.pi * r
19-- Start with polar coordinates (r,θ)
19-- Start with polar coordinates (r,θ)
20-- and get out cartesian coordinates (x,y).
20-- and get out cartesian coordinates (x,y).
21fromPolar : (Float,Float) -> (Float,Float)
21fromPolar : (Float,Float) -> (Float,Float)
22−fromPolar (r,t) = (r * N.cos t, r * N.sin t)
22+fromPolar (r,t) = (r * Native.cos t, r * Native.sin t)
24-- Start with cartesian coordinates (x,y)
24-- Start with cartesian coordinates (x,y)
25-- and get out polar coordinates (r,θ).
25-- and get out polar coordinates (r,θ).
26toPolar : (Float,Float) -> (Float,Float)
26toPolar : (Float,Float) -> (Float,Float)
27−toPolar (x,y) = (N.sqrt (x^2 + y^2), N.atan2 y x)
27+toPolar (x,y) = (Native.sqrt (x^2 + y^2), Native.atan2 y x)
29(+) : number -> number -> number
29(+) : number -> number -> number
30(-) : number -> number -> number
32(-) : number -> number -> number
31(*) : number -> number -> number
35(*) : number -> number -> number
33-- Floating point division.
38-- Floating point division.
34(/) : Float -> Float -> Float
39(/) : Float -> Float -> Float
36-- Integer division, remainder is discarded.
42-- Integer division, remainder is discarded.
37div : Int -> Int -> Int
43div : Int -> Int -> Int
39-- Finds the remainder after dividing one number by another: ``4 `rem` 3 == 1``
46-- Finds the remainder after dividing one number by another: ``4 `rem` 3 == 1``
40rem : Int -> Int -> Int
47rem : Int -> Int -> Int
42-- Perform modular arithmetic: ``7 `mod` 2 == 1``
50-- Perform modular arithmetic: ``7 `mod` 2 == 1``
43mod : Int -> Int -> Int
51mod : Int -> Int -> Int
45-- Exponentiation: `3^2 == 9`
54-- Exponentiation: `3^2 == 9`
46(^) : number -> number -> number
55(^) : number -> number -> number
48cos : Float -> Float
58cos : Float -> Float
49sin : Float -> Float
61sin : Float -> Float
50tan : Float -> Float
64tan : Float -> Float
51acos : Float -> Float
67acos : Float -> Float
52asin : Float -> Float
70asin : Float -> Float
54-- You probably do not want to use this. Because it takes `(y/x)` as the argument
73-- You probably do not want to use this. Because it takes `(y/x)` as the argument
55-- there is no way to know where the negative signs come from so the resulting
74-- there is no way to know where the negative signs come from so the resulting
56-- angle is always between π/2 and -π/2 (in quadrants I and IV).
75-- angle is always between π/2 and -π/2 (in quadrants I and IV).
57atan : Float -> Float
76atan : Float -> Float
59-- This helps you find the angle of a cartesian coordinate.
79-- This helps you find the angle of a cartesian coordinate.
60-- You will almost certainly want to use this instead of `atan`.
80-- You will almost certainly want to use this instead of `atan`.
@@ -62,21 +82,27 @@ atan : Float -> Float
62-- quadrant the angle should really be in. The result will be between
82-- quadrant the angle should really be in. The result will be between
63-- π and -π, giving you the full range of angles.
83-- π and -π, giving you the full range of angles.
64atan2 : Float -> Float -> Float
84atan2 : Float -> Float -> Float
66-- Take the square root of a number.
87-- Take the square root of a number.
67sqrt : number -> number
88sqrt : number -> number
69-- Take the absolute value of a number.
91-- Take the absolute value of a number.
70abs : number -> number
92abs : number -> number
72-- Calculate the logarithm of a number with a given base: `logBase 10 100 == 2`
95-- Calculate the logarithm of a number with a given base: `logBase 10 100 == 2`
73logBase : number -> number -> number
96logBase : number -> number -> number
97+logBase = Native.logBase
75−-- Given two numbers, returns the smaller one.
99+-- Given two comparables, returns the smaller one.
76−min : number -> number -> number
100+min : comparable -> comparable -> comparable
78−-- Given two numbers, returns the larger one.
103+-- Given two comparables, returns the larger one.
79−max : number -> number -> number
104+max : comparable -> comparable -> comparable
81-- Clamps a number within a given range. With the expression `clamp 100 200 x`
107-- Clamps a number within a given range. With the expression `clamp 100 200 x`
82-- the results are as follows:
108-- the results are as follows:
@@ -85,26 +111,40 @@ max : number -> number -> number
85-- * ` x if 100 <= x < 200`
111-- * ` x if 100 <= x < 200`
86-- * `200 if 200 <= x`
112-- * `200 if 200 <= x`
87clamp : number -> number -> number -> number
113clamp : number -> number -> number -> number
89-- An approximation of pi.
116-- An approximation of pi.
90pi : Float
117pi : Float
92-- An approximation of e.
120-- An approximation of e.
95-- Compare any two values for structural equality. Functions cannot be compared.
124-- Compare any two values for structural equality. Functions cannot be compared.
96(==) : a -> a -> Bool
125(==) : a -> a -> Bool
97(/=) : a -> a -> Bool
128(/=) : a -> a -> Bool
99(<) : comparable -> comparable -> Bool
131(<) : comparable -> comparable -> Bool
100(>) : comparable -> comparable -> Bool
134(>) : comparable -> comparable -> Bool
101(<=) : comparable -> comparable -> Bool
137(<=) : comparable -> comparable -> Bool
102(>=) : comparable -> comparable -> Bool
140(>=) : comparable -> comparable -> Bool
104-- Compare any two comparable values. Comparable values include `String`, `Char`,
143-- Compare any two comparable values. Comparable values include `String`, `Char`,
105-- `Int`, `Float`, `Time`, or a list or tuple containing comparable values.
144-- `Int`, `Float`, `Time`, or a list or tuple containing comparable values.
106-- These are also the only values that work as `Dict` keys or `Set` members.
145-- These are also the only values that work as `Dict` keys or `Set` members.
107compare : comparable -> comparable -> Order
146compare : comparable -> comparable -> Order
147+compare = Native.compare
109-- Represents the relative ordering of two things.
149-- Represents the relative ordering of two things.
110-- The relations are less than, equal to, and greater than.
150-- The relations are less than, equal to, and greater than.
@@ -112,15 +152,19 @@ data Order = LT | EQ | GT
113-- The and operator. True if both inputs are True.
153-- The and operator. True if both inputs are True.
114(&&) : Bool -> Bool -> Bool
154(&&) : Bool -> Bool -> Bool
116-- The or operator. True if one or both inputs are True.
157-- The or operator. True if one or both inputs are True.
117(||) : Bool -> Bool -> Bool
158(||) : Bool -> Bool -> Bool
119-- The exclusive-or operator. True if exactly one input is True.
161-- The exclusive-or operator. True if exactly one input is True.
120xor : Bool -> Bool -> Bool
162xor : Bool -> Bool -> Bool
122-- Negate a boolean value: `(not True == False)` and `(not False == True)`
165-- Negate a boolean value: `(not True == False)` and `(not False == True)`
123not : Bool -> Bool
166not : Bool -> Bool
125-- Equal to true. Useful as the last case of a multi-way-if.
169-- Equal to true. Useful as the last case of a multi-way-if.
126otherwise : Bool
170otherwise : Bool
@@ -131,32 +175,41 @@ otherwise = True
132-- Round a number to the nearest integer.
176-- Round a number to the nearest integer.
133round : Float -> Int
177round : Float -> Int
135-- Truncate a decimal number, rounding towards zero.
180-- Truncate a decimal number, rounding towards zero.
136truncate : Float -> Int
181truncate : Float -> Int
182+truncate = Native.truncate
138-- Floor function, rounding down.
184-- Floor function, rounding down.
139floor : Float -> Int
185floor : Float -> Int
141-- Ceiling function, rounding up.
188-- Ceiling function, rounding up.
142ceiling : Float -> Int
189ceiling : Float -> Int
190+ceiling = Native.ceiling
144-- Convert an integer into a float.
192-- Convert an integer into a float.
145toFloat : Int -> Float
193toFloat : Int -> Float
194+toFloat = Native.toFloat
147-- Convert almost any value to its string representation.
196-- Convert almost any value to its string representation.
148show : a -> String
197show : a -> String
150-- Read an integer from a string
200-- Read an integer from a string
151readInt : String -> Maybe Int
201readInt : String -> Maybe Int
202+readInt = Native.readInt
153-- Read a float from a string.
204-- Read a float from a string.
154readFloat : String -> Maybe Float
205readFloat : String -> Maybe Float
206+readFloat = Native.readFloat
156-- Function Helpers
208-- Function Helpers
158-- Function composition: `(f . g == (\\x -> f (g x)))`
210-- Function composition: `(f . g == (\\x -> f (g x)))`
159(.) : (b -> c) -> (a -> b) -> (a -> c)
211(.) : (b -> c) -> (a -> b) -> (a -> c)
161-- Forward function application `x |> f == f x`. This function is useful
214-- Forward function application `x |> f == f x`. This function is useful
162-- for avoiding parenthesis and writing code in a more natural way.
215-- for avoiding parenthesis and writing code in a more natural way.
@@ -170,6 +223,7 @@ readFloat : String -> Maybe Float
170-- |> move (10,10)
223-- |> move (10,10)
171-- |> scale 2
224-- |> scale 2
172(|>) : a -> (a -> b) -> b
225(|>) : a -> (a -> b) -> b
174-- Function application `f <| x == f x`. This function is useful for avoiding
228-- Function application `f <| x == f x`. This function is useful for avoiding
175-- parenthesis. Consider the following code to create a text element:
229-- parenthesis. Consider the following code to create a text element:
@@ -180,23 +234,30 @@ readFloat : String -> Maybe Float
181-- text . monospace <| toText "code"
235-- text . monospace <| toText "code"
182(<|) : (a -> b) -> a -> b
236(<|) : (a -> b) -> a -> b
184-- Given a value, returns exactly the same value.
239-- Given a value, returns exactly the same value.
185id : a -> a
240id : a -> a
187-- Given a 2-tuple, returns the first value.
243-- Given a 2-tuple, returns the first value.
188fst : (a,b) -> a
244fst : (a,b) -> a
190-- Given a 2-tuple, returns the second value.
247-- Given a 2-tuple, returns the second value.
191snd : (a,b) -> b
248snd : (a,b) -> b
193-- Flips the order of the first two arguments to a function.
251-- Flips the order of the first two arguments to a function.
194flip : (a -> b -> c) -> (b -> a -> c)
252flip : (a -> b -> c) -> (b -> a -> c)
196-- Change how arguments are passed to a function. This splits paired arguments
255-- Change how arguments are passed to a function. This splits paired arguments
197-- into two separate arguments.
256-- into two separate arguments.
198curry : ((a,b) -> c) -> a -> b -> c
257curry : ((a,b) -> c) -> a -> b -> c
200-- Change how arguments are passed to a function. This combines two arguments
260-- Change how arguments are passed to a function. This combines two arguments
201-- into a sigle pair.
261-- into a sigle pair.
202uncurry : (a -> b -> c) -> (a,b) -> c
262uncurry : (a -> b -> c) -> (a,b) -> c
263+uncurry = Native.uncurry