Hacker News new | ask | show | jobs
by copergi 4473 days ago
Is that a trick question? I don't know how or why you would try to do that.
2 comments

I assure you that it's not a trick question, just a poorly worded one.

Imagine that I'm making a page that converts meters to millimeters. The obvious part of the haskell code is

convert :: Double -> Double convert = 1000 *

The part which isn't obvious to me is how I get input from the user or display the result. I know how to do that in the IO monad through standard haskell, but I wouldn't know how to handle it in Haskell compile to javascript for the web browser. I would have thought that you would need a binding to the DOM to read from forms and the like.

I think fay uses its own FFI, but with haste you just use the normal FFI to call normal javascript functions the same way you would interface with C code from haskell. There's no need for special bindings or anything. You could certainly make a wrapper for jquery if you were crazy (and I'm sure someone has already done so), but this idea that you need some special DOM library to do things that javascript already does out of the box is kinda odd.
Thanks for the clarification. The key part that I was missing was the FFI. I'd encountered projects like this in the past with either no FFI or no documentation for the FFI and I couldn't figure out how to talk to the DOM. I'm more than happy to drop down to javascript for those parts, but I wasn't sure that I'd have the option.
You do it all the time in web apps. For example, changing the text of a toggle link between "show" and "hide." For example, with jQuery:

  $('#toggleLink').click(function() {
    if ($('#toggleLink').html() == 'Show') {
      showRollout();
      $('#toggleLink').html('Hide');
    } else {
      hideRollout();
      $('#toggleLink').html('Show');
    ]
  });
I think you misread something. He asked how to do it without manipulating the DOM.