无法构建项目“添加实例声明”

时间:2013-11-07 23:15:18

标签: opengl haskell

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

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

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

1 个答案:

答案 0 :(得分:1)

当您收到表单

的错误消息时
No instance for (... (... -> ...))

其中没有实例的类型是函数类型(如 - &gt;所示), 那么通常问题是函数已被应用于错误 在某处的争论数量。

然而,正如@ user2407038所说,从代码中发现的情况并不清楚,因为它取决于您粘贴的内容中未定义的函数类型。 作为猜测,也许您应该给出不同数量的参数 键盘或keyForPos。