Hacker News new | ask | show | jobs
by lalaithion 2273 days ago
The second example can be rewritten as such:

    inputWidget = let
        changeAction = do
          v <- onChange
          return (Changed (unsafeTargetValue v))
        focusAction = do
          _ <- onFocus
          return Focused
      in input [changeAction, focusAction]
and likewise for the third:

    inputWidget st = let
        focusAction = do
          _ <- onFocus
          return (st {focusCount = st.focusCount+1})
        changeAction = do
          v <- onChange
          return (st {s = unsafeTargetValue v})
      in input [focusAction, changeAction]
(I didn't compile this, so hopefully there's no major mistakes here)

Believe it or not, many Haskell programmers prefer brevity when it comes to programs like this. They're honestly not that unreadable once you learn the meaning of a few infix operators.

1 comments