Skip to content

Instantly share code, notes, and snippets.

@cobalamin
Last active April 2, 2022 09:19
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cobalamin/c1b83f5626df1409b512ce2faf05cf84 to your computer and use it in GitHub Desktop.
Save cobalamin/c1b83f5626df1409b512ce2faf05cf84 to your computer and use it in GitHub Desktop.
Elm (0.17) syntax and functionality differences for Haskell programmers
  • Types are declared with : and not ::, and the consing operator conversely is :: instead of :
  • No where clauses, only let/in
  • The standard style is different, check http://elm-lang.org/docs/style-guide for reference
  • Multiline strings are a thing with """
  • Haskell's data corresponds to type in Elm, and also, Haskell's type corresponds to Elm's type alias
  • ($) is (<|), but you don't use it all that much – Elm people like the flipped operator (|>) which lets you build something that reads like a pipeline
  • Related: Backticks will likely die soon in favour of functions that have an argument order that lends itself to pipelining with (|>)
  • Also, (.) is (<<), and a flipped version (>>) exists, but I don't see it used that much either
  • (>>=) is not an available operator and would not be polymorphic (no typeclasses, see below), and is instead commonly named SomeType.andThen – e.g. Maybe.andThen : Maybe a -> (a -> Maybe b) -> Maybe b
  • Records are nicer and more powerful, and also extensible at the type level, see http://elm-lang.org/docs/records
  • No guards and no pattern matching over multiple function definitions
  • No typeclasses and higher-kinded types
  • It's a strict language and e.g. infinite lists are not supported in Core
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment