News for hackers. Stuff that matters.
Re:Functional Programming Is Not Popular Because It Is Weird by querulous on Saturday February 27, 2016 @07:01PM (#11189082)
here's a state machine representing a lock in elm:

  type State = Locked | Unlocked
  type alias Model = State
  
  lock : Model -> Model
  lock model = Locked
  
  unlock : Model -> Model
  unlock model = Unlocked
  
  open : Model -> Bool
  open model =
    if model = Locked then True else False
and here it is in erlang:

  lock(_Lock) -> locked.
  
  unlock(_Lock) -> unlocked.
  
  open(locked) -> false;
  open(unlocked) -> true.
i think working with state machines in imperative languages is messy, mistake prone and hard to reason about. functional languages are just better for managing state

There are no comments on this comment yet.