Question

Sometimes I face to weird issue, consider following examples:

This compiles:

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']"

So does it:

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"

But if I put auxiliary functions within where block I have compilation error:

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']"

and

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"

Notice, that traceEventCoords in first example do not invokes this issue. Is it a bug?

P.S. Second example is a just an example and final code would be refactored a bit, but it holds for demonstrative purpose.

Was it helpful?

Solution

Update: This has been implemented and released in fay 0.19

Sorry for the delay! Jetlag got me :(

I think this just hasn't been implemented yet. Initially ffi was only supported on the top level, then ffi expressions were added which need the type signature next to the expression ffi "alert('foo')" :: Fay (). I don't think anyone ever got around to doing it for where statements as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top