Show Menu
Cheatography

elm Cheat Sheet (DRAFT) by

elm language

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Basic Type

-- Boolean
True : Bool
False : Bool

42 : number
-- Int or Float depending on usage
3.14 : Float

'a' : Char
"­abc­" : String

-- multi-line String
"­"­"
This is useful for holding JSON or other
content that has "­quo­tation marks".
"­"­"

Comments

-- a single line comment

{- a multiline comment
{- can be nested -}
-}

--tricks
{--} <-- this can be removed /add
add x y = x + y
--}

Literal Operation

True && not (True || False)
(2 + 4) * (4^2 - 9)
"­abc­" ++ "­def­"

List

[1..4]
[1,2,3,4]
1 :: [2,3,4]
1 :: 2 :: 3 :: 4 :: []

Condit­ionals

if powerLevel > 9000 then "OVER 9000!!!" else "meh"

--Multi-way if-expressions
if | key == 40 -> n+1
   | key == 38 -> n-1
   | otherwise -> n

--conditional behavior based on the structure of algebraic data types:
case maybe of
  Just xs -> xs
  Nothing -> []

case xs of
  hd::tl -> Just (hd,tl)
  []     -> Nothing

case n of
  0 -> 1
  1 -> 1
  _ -> fib (n-1) + fib (n-2)