gpt4 book ai didi

haskell - 您的 FFI 声明需要类型签名

转载 作者:行者123 更新时间:2023-12-02 03:39:39 25 4
gpt4 key购买 nike

有时我会遇到奇怪的问题,请考虑以下示例:

编译:

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"

但是,如果我将辅助函数放在 where block 中,则会出现编译错误:

fay: your FFI declaration needs a type signature pageX = ffi "%1['pageX']" fay: your FFI declaration needs a type signature: getParent = ffi "%1.parent()"

例如

-- ...
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 不会引发此问题。是错误吗?

附言第二个例子只是一个例子,最终代码会重构一点,但它适用于演示目的。

最佳答案

更新:已在 fay 0.19 中实现并发布

抱歉耽搁了!时差让我 :(

我认为这还没有实现。最初只在顶层支持 ffi,然后添加了 ffi 表达式,它需要表达式 ffi "alert('foo')"::Fay () 旁边的类型签名。我认为没有人会为 where 语句也这样做。

关于haskell - 您的 FFI 声明需要类型签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20910877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com