0

我正在尝试遵循本教程,当我尝试构建项目时编译器会返回此错误

No instance for (Fractional (GLdouble -> GLdouble))
  arising from a use of `keyboard'
Possible fix:
  add an instance declaration for (Fractional (GLdouble -> GLdouble))
In the first argument of `Just', namely `(keyboard pPos)'
In the second argument of `($=)', namely `Just (keyboard pPos)'
In a stmt of a 'do' block:
  keyboardMouseCallback $= Just (keyboard pPos)

这是代码

import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT  as GLUT
import Squares
import OrbitingPointOfView
import ColorCube
import Data.IORef

main = do
    (progName,_) <-  getArgsAndInitialize
    initialDisplayMode $= [WithDepthBuffer,DoubleBuffered]
    createWindow progName
    depthFunc $= Just Less

    pPos <- newIORef (90::Int, 270::Int, 2)
    keyboardMouseCallback $= Just (keyboard pPos) -- <---  causes the problem

    displayCallback $= display pPos
    reshapeCallback $= Just reshape
    mainLoop

display pPos = do
    loadIdentity
    setPointOfView pPos
    clear [ColorBuffer,DepthBuffer]
    colorCube 1
    swapBuffers

keyboard pPos c _  _ _ = keyForPos pPos c

指导我如何解决这个问题...

4

1 回答 1

1

当您收到表单的错误消息时

No instance for (... (... -> ...))

如果没有实例的类型是函数类型(如 -> 所示),那么通常问题是某个函数已应用于某个地方的错误数量的参数。

但是,正如@user2407038 所说,从您的代码中不清楚发生这种情况的位置,因为它取决于您粘贴的内容中未定义的函数类型。作为猜测,也许您应该为键盘或 keyForPos 提供不同数量的参数。

于 2013-11-08T03:08:05.800 回答