Recently I’ve invested some time to learn Elm and it’s architecture. Funny, it was made to do Redux with React based programming fun, specifically with types and syntax. Immutability from the beginning. Signals. REPL. Packages. OMG. The tooling is just amaizing! Why the heck we don’t do more of this?
This is quite aligned with where nowadays mainstream goes with EcmaScript 2024 and React 18.
Look at the state of Javascript. NPM for package management. Then PNPM, Yarn. Still no repl. Hot reload is there. JSX compilation with Babel. JSX is already a different language. Added Typescript for types. Why don’t we use just the same goodies packaged in one nice language?
And the error messages! Beautifully helpful because of types.
> greet name =
| "Hello " ++ name "!"
|
-- UNFINISHED DEFINITION -------------------------------------------------- REPL
I got stuck while parsing the `greet` definition:
3| greet name =
^
I was expecting to see an expression next. What is it equal to?
Here is a valid definition (with a type annotation) for reference:
greet : String -> String
greet name =
"Hello " ++ name ++ "!"
The top line (called a "type annotation") is optional. You can leave it off if
you want. As you get more comfortable with Elm and as your project grows, it
becomes more and more valuable to add them though! They work great as
compiler-verified documentation, and they often improve error messages!
> greet name =
| "Hello " ++ name ++ "!"
|
-- UNFINISHED DEFINITION -------------------------------------------------- REPL
> greet : String -> String
|
|
| green name =
| "hello " ++ name ++ "!"
|
-- NAME MISMATCH ---------------------------------------------------------- REPL
I just saw a type annotation for `greet`, but it is followed by a definition for
`green`:
3| greet : String -> String
4|
5|
6| green name =
^
These names do not match! Is there a typo?
green -> greet
But it was there since 2013!
Very handy syntax to do common tasks, like update field in the record. Literally this
john = { first = "John", last = "Hobson", age = 81 }
{ john | last = "Houdini" }
{ age = 81, first = "John", last = "Houdini" }
To the downsides of Elm, sadly, there is no such vast ecosystem as NPM.
Typed | Non-typed | |
---|---|---|
Frontend | Elm | ClojureScript |
Backend | Scala, Haskell | Ruby, Clojure |