Skip to content

Instantly share code, notes, and snippets.

@rupertlssmith
Last active December 4, 2018 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rupertlssmith/e8d64dedee344a6df75b9459f7bf1257 to your computer and use it in GitHub Desktop.
Save rupertlssmith/e8d64dedee344a6df75b9459f7bf1257 to your computer and use it in GitHub Desktop.
Elm Syntax
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