5 ms·
I simply love it how every single Haskell framework I've seen that has "ease of development" and "it's easy" and similar immediately devolves from this (from Co
by dmitriid 7y ago
I simply love it how every single Haskell framework I've seen that has "ease of development" and "it's easy" and similar immediately devolves from this (from Concur's docs [1]):
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/README.md https://github.com/ajnsit/concur-documentation/blob/master/R...
- chrissoundz 7y agoIt's not clear to me what you're trying to show? Are you saying the later examples look more complex?
- whateveracct 7y agoMy guess: The latter examples look unfamiliar (looks like Haskell) while the first example looks familiar to the general eye (looks like any PL) The things being compared don't even have the same purpose so idt comparing them even makes sense /shrug
- dmitriid 7y agoOf course they do. Of course they are. The simplest code change turns the code in to a monadic/functor soup.
- agentultra 7y ago... and if you program in Haskell that's exactly what you want. Programming with these abstractions is common and well supported in Haskell.
- whateveracct 7y agoGiven what the examples are doing (describing inputs) I don't see how you solve it ergonomically without higher kinded types, which in turn leads to functors etc.
- lalaithion 7y agoThe 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.
- dmitriid 7y agoI prefer the approach described here: http://www.haskellforall.com/2015/09/how-to-make-your-haskell-code-more.html http://www.haskellforall.com/2015/09/how-to-make-your-haskel...
- deleted 7y ago[deleted]
- tome 7y agoI love it too, because it is a standard and flexible way to program in Haskell!