Skip to content

Instantly share code, notes, and snippets.

@Decoherence
Last active August 29, 2015 14:09
Show Gist options
  • Save Decoherence/2cd008b1a6ba453b437b to your computer and use it in GitHub Desktop.
Save Decoherence/2cd008b1a6ba453b437b to your computer and use it in GitHub Desktop.
Haskell: Compile to JavaScript -- handle onClick and onMouseOver events.
import Haste
main :: IO ()
main = do
-- Get handle to #msg div
msg <- elemById "msg"
case msg of
Just m -> do
-- Handle onClick event
onEvent m OnClick $ \_ _ -> do
setProp m "innerHTML" "Cool!"
setStyle m "fontSize" "30"
-- Handle onMouseOver event
onEvent m OnMouseOver $ \_ -> alert ("Sweet!")
_ -> error "Element not found"
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment