[Haskell-cafe] open gl type conversions

briand at aracnet.com briand at aracnet.com
Fri May 22 05:13:59 UTC 2015


Following code

  GLFW.setWindowSizeCallback w (Just (\window w h ->
    do
     GL.viewport   $= (GL.Position 0 0, GL.Size w h)

emo1.hs:42:50:
    Couldn't match type ‘Int’ with ‘Foreign.C.Types.CInt’
    Expected type: GLsizei
      Actual type: Int
    In the first argument of ‘Size’, namely ‘w’
    In the expression: Size w h


I can never seem to figure out if i really need to do a type conversion, or just the make the appropriate type declarations.  Sometimes it seems to be a combination of both.

Part of the complication here is that w and h are, in fact, `Int` because that's there type in the  type signature of WindowSizeCallback (Window -> Int -> Int -> IO () ).

GL.Size really needs a CInt so it seems like I have to do some sort of explicit conversion, but I can never seem to figure out exactly how to find the necessary function.

Humorously i tried putting Int->CInt in hoogle, and the only thing that looked like it might be useful was unsafeCoerce, but I'm pretty sure that's not the right answer.

I was wondering if someone could enlighten me on exactly how you can trace out the solution to this sort of problem because it seeems to come up often (see, for example my confusion over FFTW r).


Brian


More information about the Haskell-Cafe mailing list