Skip to content

Instantly share code, notes, and snippets.

@RudolfVonKrugstein
RudolfVonKrugstein / gist:3122476
Created July 16, 2012 12:41
UHC global objects imports
foreign import js "saveObject(%1, %2)"
jsSaveObject :: JSString -> a -> IO ()
saveObject :: String -> a -> IO ()
saveObject s a = jsSaveObject (toJS s) a
foreign import js "loadObject(%1)"
jsLoadObject :: JSString -> IO a
loadObject = jsLoadObject . toJS
@RudolfVonKrugstein
RudolfVonKrugstein / gist:3122477
Created July 16, 2012 12:42
haste global objects js
function jsSaveGlobalObject(name, obj) {
allObjects[name] = obj;
return [1,0];
}
function jsLoadGlobalObject(name) {
return [1,0,allObjects[name]];
}
@RudolfVonKrugstein
RudolfVonKrugstein / gist:3122479
Created July 16, 2012 12:43
haste global objects haskell
foreign import ccall jsSaveGlobalObject :: JSString -> Ptr a -> IO ()
foreign import ccall jsLoadGlobalObject :: JSString -> IO (Ptr a)
saveGlobalObject :: String -> a -> IO ()
saveGlobalObject name obj = jsSaveGlobalObject (toJSStr name) (toPtr obj)
loadGlobalObject :: String -> IO a
loadGlobalObject name = do
  ptr <- jsLoadGlobalObject (toJSStr name)
  return $ fromPtr ptr
@RudolfVonKrugstein
RudolfVonKrugstein / gist:3122489
Created July 16, 2012 12:44
UHC get context2d
data Document
data Context2D
data Canvas
foreign import js "document"
    document :: IO Document
foreign import js "%1.getElementById(%2)"
    jsGetElementById :: Document -> JSString -> IO Canvas
getElementById doc = jsGetElementById doc . toJS
foreign import js "%1.getContext('2d')"
@RudolfVonKrugstein
RudolfVonKrugstein / gist:3122492
Created July 16, 2012 12:45
UHC importing drawing functions
foreign import js "%1.fillRect(%*)"
fillRect :: Context2D -> Double -> Double -> Double -> Double -> IO ()
foreign import js "%1.setFillColor(%*)"
setFillColor :: Context2D -> Double -> Double -> Double -> Double -> IO ()
@RudolfVonKrugstein
RudolfVonKrugstein / gist:3122496
Created July 16, 2012 12:46
haste drawing javascript
function jsGetContext2d(canvas, _) {
return [1,0,canvas.getContext("2d")];
}
function jsFillRect(context, x, y, width, height, _) {
context.fillRect(x,y,width,height);
return [1,0];
}
function jsSetFillColor(context, color, _) {
@RudolfVonKrugstein
RudolfVonKrugstein / gist:3122499
Created July 16, 2012 12:46
haste drawing haskell part
import Haste.Prim
import Haste.DOM
newtype Context2D = Context2D JSAny
foreign import ccall "jsGetContext2D"
jsGetContext2d :: Elem -> IO Context2D
getContext2d name = withElem name getContext2D
foreign import ccall "jsFillRect"
fillRect :: Context2D -> Double -> Double -> Double -> Double -> IO ()
<command-line>:0: warning: "__STDC__" redefined [enabled by default]
<built-in>:0: note: this is the location of the previous definition
<command-line>:0: warning: "__STDC__" redefined [enabled by default]
<built-in>:0: note: this is the location of the previous definition
containers-0.4.1.0/Data/Set.hs:22: warning: missing terminating " character [enabled by default]
containers-0.4.1.0/Data/Set.hs:27: warning: missing terminating " character [enabled by default]
containers-0.4.1.0/Data/Set.hs:496: warning: missing terminating ' character [enabled by default]
containers-0.4.1.0/Data/Set.hs:515: warning: missing terminating ' character [enabled by default]
containers-0.4.1.0/Data/Set.hs:606: warning: missing terminating ' character [enabled by default]
containers-0.4.1.0/Data/Set.hs:607: warning: missing terminating ' character [enabled by default]
EH analyses: Type checking
containers-0.4.1.0/Data/Set.hs-cpp:521-536:
Occur cycle:
type var: 4_13881_2
to type : {! i_4_13881_1[] !} -> v_4_13881_2
containers-0.4.1.0/Data/Set.hs-cpp:521-536:
Occur cycle:
type var: 4_14227_2
to type : {! i_4_13881_1[] !} -> v_4_14227_2
containers-0.4.1.0/Data/Set.hs-cpp:521-536:
<!DOCTYPE html><html><head><title>Example</title>
<script type="text/javascript" src="example.js"></script>
</head>
<body>
Input 1: <input type="text" id="form1">
Input 2: <input type="text" id="form2">
</body>
</html>