Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Iterating Array

  • Loading branch information...
commit fb89b90dbe61e2b8cc50a2d15d7734a19ce11ad4 1 parent 9cddb93
@spockz spockz authored
View
22 resources/static/hjs/Models.hs
@@ -1,5 +1,10 @@
module Models where
+import Language.UHC.JScript.ECMA.String
+import Language.UHC.JScript.Primitives
+import Language.UHC.JScript.Types
+
+
type ProofResult = String -- I want to make an enum of this
data ProofTreeNode = Node {
@@ -10,9 +15,24 @@ data ProofTreeNode = Node {
}
data Rule = Rule {
- rule :: String
+ id :: Int,
+ ro :: Int,
+ rule :: JSString
}
+data JSRulePtr
+type JSRule = JSPtr JSRulePtr
+
+instance FromJS JSRule Rule where
+ fromJS = jsRule2Rule
+
+jsRule2Rule :: JSRule -> Rule
+jsRule2Rule ptr = Rule {
+ id = getAttr "id" ptr,
+ ro = getAttr "ro" ptr,
+ rule = getAttr "rule" ptr
+ }
+
proofTreeNode = Node "" "" [] ""
-- class exports.ProofTreeNode extends Backbone.Model
View
37 resources/static/hjs/jcu.hs
@@ -3,19 +3,27 @@ module JCU where
import Control.Monad (liftM)
-import Language.UHC.JScript.Types (JS, toJS)
+import Data.List
+
+
+
+import Language.UHC.JScript.Types (JS, toJS, fromJS)
import Language.UHC.JScript.Primitives
import Language.UHC.JScript.JQuery.JQuery
-import Language.UHC.JScript.ECMA.Array
import Language.UHC.JScript.W3C.HTML5 as HTML5
-import Language.UHC.JScript.Assorted (alert)
+import Language.UHC.JScript.ECMA.String
+
+import Language.UHC.JScript.Assorted (alert , _alert)
import Language.UHC.JScript.JQuery.Ajax as Ajax
import qualified Language.UHC.JScript.JQuery.AjaxQueue as AQ
----
-- App
----
+-- import Language.UHC.JScript.ECMA.Array
+
+import Array
import Templates
import Models
@@ -30,8 +38,6 @@ ajaxQ url onSuccess onFail = do
})
onSuccess
onFail
- alert "meh"
-
register_events :: [(String, JEventType, JEventHandler)] -> IO ()
register_events = mapM_ (\ (e, event, eh) -> do elem <- jQuery e
@@ -67,12 +73,25 @@ initialize = do -- Rendering
-- Proof tree
-- Rules list
- ajaxQ "http://localhost:8000/rules/stored" addRules (\x y z -> return ())
+ ajaxQ "/rules/stored" addRules noop
+ where noop :: AjaxCallback (JSPtr a)
+ noop = (\x y z -> return ())
-addRules :: AjaxCallback (JSPtr a)
-addRules obj str obj2 = do alert "rules!"
- return ()
+addRules :: AjaxCallback (JSArray JSRule)
+addRules obj str obj2 = do -- slet rules = (Data.List.map fromJS . elems . jsArrayToArray) obj
+ f <- mkEachIterator (\ idx e -> do let ruleElem = jsRule2Rule e
+ _alert (rule ruleElem)
+ alert (jsStringToString $ rule ruleElem)
+
+ return ())
+
+ alert "rules!"
+ each' obj f
+ return ()
+ where ruleF :: Int -> JSRule -> IO ()
+ ruleF idx e = do let ruleElem = fromJS e
+ (alert . fromJS . rule) ruleElem
foreign import jscript "jQuery.noop()"
noop :: IO (JSFunPtr (JSPtr a -> String -> JSPtr b -> IO()))
View
2  resources/static/hjs/makefile
@@ -3,4 +3,4 @@ LANGUAGE_DIR = /Users/alessandro/Documents/Uni/xp/uhc-jscript/uhc-jscript/src
all: build
build:
- ${UHC} --import-path=${LANGUAGE_DIR} -tjscript --no-recomp -O,2 jcu.hs
+ ${UHC} --import-path=${LANGUAGE_DIR} -tjscript --no-recomp --no-hi-check -O,2 --dump-core-stages=1 jcu.hs
Please sign in to comment.
Something went wrong with that request. Please try again.