Last active
December 4, 2018 21:16
-
-
Save rupertlssmith/e8d64dedee344a6df75b9459f7bf1257 to your computer and use it in GitHub Desktop.
Elm Syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BasicSyntax exposing (..) | |
fact : Int -> Int | |
fact n = | |
if n == 0 then | |
1 | |
else | |
n * fact (n - 1) | |
map : (a -> b) -> List a -> List b | |
map fn vals = | |
case vals of | |
[] -> | |
[] | |
v :: vs -> | |
(fn v) :: map fn vs | |
squares = | |
let | |
sqfn = | |
(\x -> x * x) | |
in | |
map sqfn ([ 1, 2, 3 ] ++ [ 4, 5, 6 ]) | |
type alias Model = | |
{ user : Maybe User | |
, state : UIState | |
, size : ( Int, Int ) | |
} | |
type UIState | |
= Sizing | |
| LogIn | |
| Loading | |
| Ready | |
vals : List { a | val : Int } -> List Int | |
vals vs = | |
map .val vs | |
noSubtyping = | |
-- a is {} in 1, and a is { bad : True} in 2, so will fail type checking | |
vals [ { val = 2 }, { val = 3, bad = True } ] | |
type Maybe a | |
= Nothing | |
| Just a | |
divByZero = | |
4 // 0 | |
floatDivByZero = | |
4.0 / 0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment