ELM to someone coming from JS
the language with a weird cube puzzle as a logo that explodes into different shapes!
- static, functional
- whitespace matters (like in python)
- seems like duck typing (alias with same type signature as another type is the same type)
- watch this from the creator of elm!
- avoid premature refactoring (refactoring is like playing code golf at work!), let files grow! (the compiler’s got your back)
- always ask ‘why’ when thinking ‘I should refactor this’, are they the same or ar they just similar?
values
True
1
1.1
"fantastic"
'f'
[ "list", "of", "strings" ]
("tuple", "of", 42)
{ a = "record", b = "of", c = 4, d = "things"}
- all elements in a list must have the same type
- lists are kinda like JS arrays
- tuples are weirdly constrained to min 2, and max 3 elements! (I guess it does fine for most things?), immutable, also
Tuple.first
, Tuple.second
, Tuple.third
… WEIRD!!
- records are like JS objects using
=
- updating records is done by creating new records (functional!), pre-populate new record with existing using
|
to reinvent the square wheel:
oldWheel = { name = "wheel", shape = "circle", radius = 100 }
newWheel = { oldWheel | shape = "square" }
functions
the javascript
const shout = (word: string) => {
return `${word}!!!`
}
becomes
shout word =
word ++ "!!!"
- no token prefixes the definition of a function
- no parentheses indicate the arguments of a function
- just start with the function
name
, then spaces
to separate param signature, lastly finish signature with an =
- string manipulation: concatenation operator is
++
- types are inferred