from Hacker News

Generate semi-dynamic UIs with Haskell

by pka on 3/29/20, 12:25 PM with 13 comments

  • by dmitriid on 3/30/20, 2:26 PM

    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/R...

  • by ivanbakel on 3/30/20, 2:26 PM

    Cool application of Haskell's purity-by-default. I'm slightly surprised this takes the approach of enumerating the whole input space to get all states, though - given that termination for big spaces isn't a priority, why not just explore all paths instead? Then you could return `Int` as much as you wanted, if the actual code only goes through finitely many different values.