by dmitriid · 6y ago · 0 comments
hello = do
button [onClick] [text "Say Hello"]
text "Hello Sailor!"
into this: inputWidget = input [(Changed <<< unsafeTargetValue) <$> onChange, Focused <$ onFocus]
or this: inputWidget st = input [st {focusCount = st.focusCount+1} <$ onFocus
, ((\s -> st {currentText = s}) <<< unsafeTargetValue) <$> onChange]
for even the slightest modifications (which are not even complex in this case) These instances, allow a natural handling of
return values using <$>, <*>, <$, monadic
do-notation, etc
Right...[1] https://github.com/ajnsit/concur-documentation/blob/master/R...
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.
The things being compared don't even have the same purpose so idt comparing them even makes sense /shrug
The simplest code change turns the code in to a monadic/functor soup.