【发布时间】:2013-10-01 19:04:46
【问题描述】:
我正在使用 Haskell openGL 绑定来尝试制作粒子生成器。 我想将有关粒子的信息存储在记录中,然后我可以传入字段并在适当的时候更新它们。
所以记录中的一个位置存储为:
data Particle = Particle { pos :: Vertex2 GLfloat }
并像这样设置:
Particle { pos = Vertex2 1 (0::GLfloat) }
然后我传入粒子并尝试像这样检索值:
drawParticle :: Particle -> IO ()
drawParticle part =
(pos part) >>= \(Vertex2 x y) ->
print x
我得到的错误:
Couldn't match type `Vertex2' with `IO'
Expected type: IO GLfloat
Actual type: Vertex2 GLfloat
In the return type of a call of `pos'
In the first argument of `(>>=)', namely `(pos part)'
In the expression: (pos part) >>= \ (Vertex2 x y) -> print x
我对数据类型 Vertex2 以及为什么必须使用单个 GLfloat 而不是两个来声明它感到有些困惑。如何从数据类型 Vertex2 GLfloat 中提取数字? (这就是我如何将 Vertex2 1 (0::GLfloat) 提取为 x = 1.0, y = 0.0?
【问题讨论】: