有时我会遇到奇怪的问题,请考虑以下示例:
编译:
renderFrame :: Frame -> Fay ()
renderFrame frame = do
stack <- getStack
if length stack > 0
then (do
let e = head stack
traceEventCoord e)
else (do return ())
reqFrame renderFrame
emptyStack
where traceEventCoord :: Event -> Fay ()
traceEventCoord e = do
eX <- pageX e
eY <- pageY e
let str = show eX ++ " x " ++ show eY
trace <- elById "trace"
if isNull trace
then return ()
else elSetHtml (fromNullable trace) str
pageX :: Event -> Fay Int
pageX = ffi "%1['pageX']"
pageY :: Event -> Fay Int
pageY = ffi "%1['pageY']"
所以:
getParentGroups :: Fragment -> Fay [Fragment]
getParentGroups f = do
p <- getParent f
nn <- nodeName (fromNullable p)
return [fromNullable p]
getParent :: Fragment -> Fay (Nullable Fragment)
getParent = ffi "%1.parent()"
nodeName :: Fragment -> Fay String
nodeName = ffi "%1.node.nodeName"
但是如果我将辅助函数放在块中我有编译错误:
fay: your FFI declaration needs a type signature pageX = ffi "%1['pageX']"
fay: your FFI declaration needs a type signature: getParent = ffi "%1.parent()"
E.g。
-- ...
where traceEventCoord :: Event -> Fay ()
traceEventCoord e = do
eX <- pageX e
eY <- pageY e
let str = show eX ++ " x " ++ show eY
trace <- elById "trace"
if isNull trace
then return ()
else elSetHtml (fromNullable trace) str
pageX :: Event -> Fay Int
pageX = ffi "%1['pageX']"
pageY :: Event -> Fay Int
pageY = ffi "%1['pageY']"
和
getParentGroups f = do
p <- getParent f
nn <- nodeName (fromNullable p)
return [fromNullable p]
where
getParent :: Fragment -> Fay (Nullable Fragment)
getParent = ffi "%1.parent()"
nodeName :: Fragment -> Fay String
nodeName = ffi "%1.node.nodeName"
请注意,第一个示例中的traceEventCoords
不会调用此问题。
这是一个错误吗?
P.S。第二个例子只是一个例子,最终的代码会稍微重构一下,但它只是出于演示目的。
答案 0 :(得分:1)
更新:这已经在fay 0.19实施和发布
抱歉延误了! Jetlag让我:(
我认为这还没有实施。最初ffi仅在顶级支持,然后添加ffi表达式,需要表达式ffi "alert('foo')" :: Fay ()
旁边的类型签名。我认为没有人能够在任何陈述中做到这一点。