Stephen
Stephen

Reputation: 2843

How to convert a Double to a Foreign.C.Types.CInt

I am trying to set initialWindowSize which takes a Graphics.UI.GLUT.Size based on the output of another function with returns some Doubles.

First I stupidly plugged in my Doubles and of course I get this:

Couldn't match type `Double' with `Foreign.C.Types.CInt'
Expected type: GLsizei
  Actual type: Double
In the first argument of `G.Size', namely `x'
In the second argument of `($=)', namely `G.Size x y'
In a stmt of a 'do' block: initialWindowSize $= G.Size x y

I can't seem to find any functions which will allow me to convert my Doubles into CInts

I tried toInteger but I get:

Couldn't match type `Integer' with `Foreign.C.Types.CInt'

What is the right way to do this conversion?

Upvotes: 0

Views: 936

Answers (1)

Piotr Miś
Piotr Miś

Reputation: 981

What about:

round (2.25 :: Double) :: CInt

Or even better:

round (2.25 :: Double) :: GLsizei

Upvotes: 4

Related Questions