2015-06-12 82 views
0

我正在努力使我的數據類型一般而不是採取在OpenGL類型GLfloat。所以我開始把它做成a,然後用所有東西代替。Haskell - 無法推斷...從上下文錯誤 - OpenGL AsUniform類類型

現在,我已經達到了設置統一變量的地步,但他們採用了GLfloat的。我使用了一個名爲GLUtil的庫,它使得它更容易一些,它提供了一個類AsUniform來檢查類型是否可以是一個統一的變量。我堅持它在我的類型簽名,但它仍然給我一個錯誤。下面的代碼:

-- | Sets the modelview and projection matrix uniform variables. 
mvpUnif :: (GL.UniformComponent a, Num a, Epsilon a, Floating a, AsUniform a) => (GLState a) -> ShaderProgram -> IO() 
mvpUnif state p = do 
-- Check if view and projection matrices are there, else set them to the identity. 
let vMat = case vMatrix state of 
    Just v -> v 
    Nothing -> getIdentity 
let pMat = case pMatrix state of 
    Just p -> p 
    Nothing -> getIdentity 
-- Multiply model and view matrix together. 
let mvMatrix = vMat !*! mMatrix state 
setUniform p uModelViewMatrixVar mvMatrix 
setUniform p uProjectionMatrixVar pMat 

和錯誤:

Could not deduce (AsUniform (V4 (V4 a))) 
    arising from a use of `setUniform' 
from the context (GL.UniformComponent a, 
        Num a, 
        Epsilon a, 
        Floating a, 
        AsUniform a) 
    bound by the type signature for 
      mvpUnif :: (GL.UniformComponent a, Num a, Epsilon a, Floating a 
, 
         AsUniform a) => 
         GLState a -> ShaderProgram -> IO() 
    at src\Graphics\FreeD\Shaders\DefaultShaders.hs:194:12-119 
In a stmt of a 'do' block: 
    setUniform p uModelViewMatrixVar mvMatrix 
In the expression: 
    do { let vMat = ...; 
     let pMat = ...; 
     let mvMatrix = vMat !*! mMatrix state; 
     setUniform p uModelViewMatrixVar mvMatrix; 
     .... } 
In an equation for `mvpUnif': 
    mvpUnif state p 
     = do { let vMat = ...; 
      let pMat = ...; 
      let mvMatrix = ...; 
      .... } 

V4由AsUniform的一個實例,以及M44,這對於(V4(V4一)),其I型想到可能是這個問題,所以我不知道爲什麼它的行爲。

下面是該類的來源:

http://hackage.haskell.org/package/GLUtil-0.8.5/docs/Graphics-GLUtil-Linear.html

謝謝!

回答

1

嘗試增加-XFlexibleContexts和約束,從字面上看,你現有的答案:

{-# LANGUAGE FlexibleContexts #-} 

mvpUnif :: (GL.UniformComponent a 
      , Num a 
      , Epsilon a 
      , Floating a 
      , AsUniform a 
      , AsUniform (V4 (V4 a)) 
      ) => (GLState a) -> ShaderProgram -> IO() 

一般情況下是不屬於inferrable,或者限制需要被傳遞地包含在所有調用點約束常規。這種情況一直髮生在MonadState等人身上。在這種情況下,setUniform是罪魁禍首。

+0

不可以:/。同樣的錯誤。把它放在頂部和我的cabal文件中,我嘗試將sig改爲'AsUniform(V4(V4 a))',但這並沒有影響到它。也許GLUtil的軟件包頁面可能會閃耀一些爲什麼它不起作用的光芒,你認爲? – Gentatsu