Skip to content

Instantly share code, notes, and snippets.

@eamelink
Created June 5, 2014 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eamelink/e9adbe6f994cabae273b to your computer and use it in GitHub Desktop.
Save eamelink/e9adbe6f994cabae273b to your computer and use it in GitHub Desktop.
HelloWorld.purs typing questions
module HelloWorld where
import Data.Either
import Prelude
import Data.Foreign
import Control.Monad.Eff
import qualified Control.Monad.JQuery as J
import Debug.Trace
main = J.ready $ do
-- Get the document body
b <- J.body
-- Create a text box
div <- J.create "<div>"
input <- J.create "<input>"
"Your Name: " `J.appendText` div
input `J.append` div
div `J.append` b
-- Create a paragraph to display a greeting
greeting <- J.create "<p>"
{ color: "red" } `J.css` greeting
greeting `J.append` b
-- Listen for change events on the text box
flip (J.on "change") input $ \_ -> do
Right name <- parseForeign read <$> J.getValue input
trace $ "Name changed to " ++ name
J.setText ("Hello, " ++ name) greeting
{-
The above compiles. Now, in `psci`, I do:
> :t HelloWorld.main
forall t95. Control.Monad.Eff.Eff (trace :: Debug.Trace.Trace, dom :: Control.Monad.JQuery.DOM | t95) Control.Monad.JQuery.JQuery
Compiling HelloWorld
So I assume that I should be able to add that as a type to main:
main :: forall t95. Control.Monad.Eff.Eff (trace :: Debug.Trace.Trace, dom :: Control.Monad.JQuery.DOM | t95) Control.Monad.JQuery.JQuery
But if I do that, I get an error:
Error at /Users/eamelink/projects/personal/purethings/app/assets/purescript/helloworld.purs line 11, column 8:
Error in declaration main
Cannot unify (dom :: Control.Monad.JQuery.DOM | u13) with (trace :: Debug.Trace.Trace | t952)
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment