2014-07-26 88 views
0
foreign import subscribeEventedOnPrime 
    "function subscribeEventedOnPrime(n){ \ 
    \ return function(fn){     \ 
    \ return function(obj){    \ 
    \  return function(){    \ 
    \   obj.addEventListener(n, fn); \ 
    \   return obj;     \ 
    \  };        \ 
    \  };        \ 
    \ };         \ 
    \}" :: forall d a o eff. 
     String -> 
     (d -> a) -> 
     o -> 
     Eff (customEvent :: CustomEvent | eff) o 

subscribeEventedOn n f o = subscribeEventedOnPrime n (\e -> do 
    trace "wtf" -- if this line is removed, everything seems to work 
    f $ newEvent e."type" e."detail" 
) o 

一个do代码块是否有一行vs多行,似乎影响代码是否实际被调用。我错过了什么?加入做代码块,停止代码执行

回答

1

我认为这是因为通过intoducing的trace你让d -> a成类似

forall e. d -> Eff (trace :: Trace | e) Unit 

这意味着它不会被评估,除非您使用unsafeInterleaveEff或类似的东西,实际运行它。

我不是100%确定的,但编译器可能不应该让你使用do根本没有踪迹,我必须调查一下。

+0

嘿,有没有什么办法可以得到一对一的支持呢?我一直在为这几天的单元测试挣扎,而这个问题似乎是语法。 – Fresheyeball