8: Types with Help - JSToElm
All Episodes

8: Types with Help

Compiler help. The promise of Elm is no runtime errors. This has been proven in large code bases like that of NoRedInk. But how can it make such a claim? Elm has a strong, static type system.

News and updates

  • Elm conf was last week, and it was fun to follow via slack and twitter. It sounds like it was as amazing as I expected it to be. Really wish I could have made it. Brian Hicks, the organizer, has started releasing the videos of the talks. I was hoping to binge watch them all, but they are being released 2 per day. I like this idea. Gives me a chance to focus on just 2 for that day, and enjoy them. Rather than skipping around from some to others. The motivation was really to give all the speakers due credit for their hard work, and not get buried in an avalanche style release. Once they are all releases, I’ve been making notes on each video as they’re coming out, and hopfully I’ll be able to incorporate it into an upcoming episode soon.
  • Looking forward, Elm Europe 2018 is next Engineering School in Villejuif (near Paris, France) on July, 5-6th. Calling for papers…

Types with that for can haz help

  • You can’t save yourself from … yourself (SELECTEDPHOTO not SELECTPHOTO)!!!!

    • Spent probably 40 minutes wondering why it wasn’t working.
    • Now if you’re out there gilbert, yes, union types. I got it, I just haven’t gotten to that yet!!
  • Creating view model functions

    • if then, else syntax
  • Elm is curried, what’s that mean? Haskell Brooks Curry. Where do I know that name from? At this point should probably pick up a biography of this guy!

    • Understand partial function application
    • JS in contrast is not. It’s tupled, meaning it expects all the arguments upfront.
    • Remember to put in the what does that look like in JS, Richard does a very good job of this.
  • Type Annotations

    • these I feel like are pretty straight forward.
    • greetings : String -> String
    • This would read as function greetings takes type of string and returns a string
    • map : (a -> b) -> List a -> List b
    • The parens help to disambiguate and direct order of operations, just like in map. So here we’d say, map takes a function, that function takes a type and returns a different type, and map also takes a List of type a, then returns a List of type b.
  • Type variables

    • A type variable represents more than one possible type. Type variables have lowercase names, making them easy to tell them apart from concrete types like String, which are always capitalized.
    • List a -> Array a Would read, List of type a, where ‘a’ is whatever, strings, numbers, records. List of type a will return an Array of type a. This Array of type is the same as the List type that we started with.
  • Type aliases

    • allow you to attach human readable names to existing types.
    • now instead of using that whole record for a type, we can use ‘User’, and have a better understanding of what the record is refering to, but also make our types more concise.
  type alias User =
  { name : String
  , hobbies : List String
  , age : Int
  , beard : Bool
  • Union Types

    • Also known as: Union types are sometimes called tagged unions. Some communities call them ADTs.
    • Feel like we can do a whole show on union types. So, that’s what we’ll do!

Current work on Photo Groove from Elm in Action



Published 5 Oct 2017

A show about learning Elm, Functional Programing, and generally leveling up as a JS developer.
JavaScript To Elm on Twitter