Haskell and Elm in Production

AN UNEXPECTED JOURNEY

Who am I?

  • Senior Web Developer at LiveView Technology
  • Father of two
  • FP Programmer
  • Love LoL (B5 for life)

The Plan

  • Setting up the context
  • Picking a frontend language or framework
  • Picking a backend language or framework
  • Experience with Elm
  • Experience with Haskell

Setting up the context

What we had

  • CakePHP spaghetti mess
  • Copy-Pasta of code everywhere
  • Blend of JS libs meshed together
  • Random jQuery

What we wanted

  • Maintainability, Maintainability, Maintainability
  • Multiple SPA apps to meet our different customer needs
  • Unified cohesive frontend
  • Properly architected backend

Skills we had

  • CakePHP
  • CodeIgniter
  • Magento
  • Angular 1.x
  • jQuery
  • Vanilla JS
  • The ability to adapt

Questions?

Picking a frontend language

What we wanted

  • Something that was "better" then just regular JS
  • Framework that would not get in the way
  • Something with good documentation

What we tried

  • Elm
  • Didn't feel a need to try anything else

Questions?

Picking a Backend Language

What we Originally wanted

  • Able to handle changing requirements easily
  • Something we were familiar with
  • Simple, non-bloated framework
  • Maintainability, Maintainability, Maintainability

So we chose:

PHP

But What framework?

Decided to look at micro-frameworks

  • Bullet
  • Slim
  • Silex

and we chose ...

Bulletphp

  • Functional (Elm is functional)
  • Used composer
  • Had a good recommended project structure

... but

  • Didn't seem actively maintained
    • last commit was a few years ago
  • Small community
  • Didn't like php for websockets

If not PHP then what?

  • NodeJS
  • Go
  • Rust
  • Haskell
  • Something else?

exploration

  • Which had websocket support?
  • Which had good mysql support?
  • Which had a good community?
  • Which had a "good" type system? 

... and we chose?

Never let anyone know the truth: we write total functions in strong types because we’re not clever enough to spot all the pitfalls without them

- i-am-tom

Haskell

  • Yesod has plugins for websockets
  • Persistent allowed for type safe SQL
  • Esqueleto allowed for type safe custom queries
  • Community was very friendly, new book made learning much easier
    • http://haskellbook.com/

Questions?

Experience with ELM

Elm is its own paradigm

  • Thinking OOP like causes more work
  • Originally design to be a UI language
  • The Elm Architecture
  • Use types to guide design

What I Love

  • No run-time exceptions
  • No null
  • Compiler is your friend
  • Refactoring is amazing
  • No "fancy" type system features

What is frustrating

  • Direct JavaScript inter-opt

  • Some compiler messages
  • No "fancy" type system features

Community and Tooling

  • Enforced Semantic Versioning
  • Helpful Slack channel
  • Elm-Format
  • Young, but getting better every day

Questions?

Experience with Haskell

What surprised me

  • That I don't need a PhD
  • Can program at low and high levels
  • Debugging is different due to lazy eval

A paradigm is a mindset about how you look at your code.

- Anjanna Vakil

(Programming Across Paradigms https://www.youtube.com/watch?v=Pg3UeB-5FdA)

Yesod

  • Adheres to the Web Application Interface (WAI)
  • Type safe URLs
  • Type safe SQL
  • Like a piecemeal "Ruby on Rails" framework

What I love

  • Exceptions are used exceptionally
  • Type safe business logic
  • No null
  • Can run it "interpretted", interpreted, or compiled
  • Stack
  • Types become micro unit tests

What is frustrating

  • The seemingly huge emphasis on Monads
  • Because of advanced types, compiler message can be cryptic
  • Harder to learn if you already know OOP
    • Simple Made Easy - Rich Hickey

Community and Tooling

  • Stack is amazing! (No more cabal hell)
  • There are IRC channels and active slack channels in the Functional Programming slack
    • http://fpchat-invite.herokuapp.com/
    • https://www.haskell.org/irc
  • Hoogle
    • http://hoogle.haskell.org/
  • Hackage
    • https://hackage.haskell.org/
    • https://www.stackage.org/

Questions?

Thank YOU!

@sbditto85

Haskell And Elm in Production

By sbditto85

Haskell And Elm in Production

  • 1,010