(+) :: Number -> Number -> Number
(-) :: Number -> Number -> Number
# Money -> Number | |
money-sum = (money) -> money |> obj-to-pairs |> map apply (*) |> sum | |
# Number -> Money | |
to-money = (sum) -> | |
sum-places = "0000#sum" |> chars |> reverse |> map parse-int | |
10000: floor sum / 10000 | |
5000: if sum-places.3 >= 5 then 1 else 0 | |
1000: if sum-places.3 >= 5 then sum-places.3 - 5 else sum-places.3 | |
500: if sum-places.2 >= 5 then 1 else 0 |
# (a -> b) -> Promise a -> Promise b | |
map-promise = (f, promise) --> promise.then (x) -> new Promise (resolve) -> resolve f x | |
# (a -> b) -> Maybe a -> Maybe b | |
map-maybe = (f, maybe) --> | |
| maybe? => f maybe | |
| _ => null | |
# (a -> b) -> [a] -> [b] | |
map-list = (f, xs) --> [f x for x in xs] |
Promise a | |
Maybe a = (a | Undefined) | |
Either a b = (a | b) | |
Tuple a b = [a, b] |
S = (f) -> (g) -> (x) -> (f x) (g x) | |
K = (p) -> (q) -> p | |
I = (a) -> a | |
(((S K (S I)) K) 'Hello, world') console.log |
piyo = (f, x) --> | |
| f x => 1 + piyo f, f x | |
| _ => 0 | |
/* piyo.js | |
var piyo = function(f) { | |
return function(x) { | |
return f(x) ? 1 + piyo(f)(f(x)) : 0; | |
}; | |
}; |
import Graphics.Element exposing (..) | |
s f g x = f x (g x) | |
k p q = p | |
i a = a | |
main : Element | |
main = | |
show (s k k "Hello, world!") |
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
main = div | |
[style [("font-size", "64px")]] | |
[text "Hello, world!"] |
import Graphics.Element exposing (show) | |
import List exposing (product) | |
factorial n = product [1..n] | |
main = show <| factorial 10 -- 3628800 |
import Graphics.Element exposing (show) | |
import String exposing (repeat) | |
(*) : String -> Int -> String | |
(*) = flip repeat | |
main = show ("foo" * 4) |