hackage vector-space-opengl

Adam Foltzer acfoltzer at gmail.com
Sun May 20 20:35:58 CEST 2012


Hi Nikolay,

I am glad you found my work helpful, and thank you for the suggestions!
Please find my responses interspersed below.

On Sun, May 20, 2012 at 5:59 AM, Nikolay Orlyuk <virkony at gmail.com> wrote:

While looking into OpenGL/TH.hs I found that it quite incomplete and I
> understand why. That suggestion at stackoverflow results in a bit
> boilerplate code:
>
> deriveScalar, deriveScalarAdditiveGroup, deriveScalarVectorSpace,
> deriveScalarAffineSpace :: [Name] -> Q [Dec]
> deriveScalar ts = concat <$> forM decls (\qf -> qf ts)
>     where decls = [ deriveScalarAdditiveGroup
>                   , deriveScalarVectorSpace
>                   , deriveScalarAffineSpace
>                   , deriveScalarInnerSpace
>                   ]
> deriveScalarVectorSpace ts = concat <$> mapM f ts where
>     f tn = do
>         t <- [t| $(conT tn) |]
>         vs <- [t| VectorSpace |]
>         (AppT (ConT s) _) <- [t| Scalar () |] -- dummy type to extract
> Scalar name
>         (VarE h) <- [e| (*^) |] -- refer to actual (*^) from VectorSpace
>         e <- [e| (*) |] -- (*) from Num
>         return [
>             InstanceD [] (AppT vs t) [
>                 TySynInstD s [t] t,
>                 ValD (VarP h) (NormalB e) []
>             ]]
>
> I've not had an opportunity to work this since I finished the graphics
course that motivated its creation, but would be happy to take your
modifications as a github pull request (
https://github.com/acfoltzer/vector-space-opengl). I just couldn't justify
the time getting the TH to work fully when I was chasing a deadline on a
semester project.


> It's kinda partially checked and partially constructed. BTW, rather than
> depending on OpenGL its better to use Graphics.Rendering.OpenGL.Raw I
> think. Also there is types GLclampd and GLclampf (I suspect that they
> somehow related with OpenCL).
>

Regarding the dependency on OpenGL vs. OpenGLRaw, some of the semantic
versions of the Data.Tensor types (Normal*, Color*) are defined in the full
OpenGL package, so I will keep the dependency because of that.

While scalar types doesn't differ whether they are absolute whether they
> are not. Data.Tensor makes difference between Vertex and Vector. I suspect
> that made especially for this case: instance AffineSpace a => AffineSpace
> (Vertex2 a) where type Diff (Vertex2 a) = Vector2 (Diff a)
> I.e. Diff Vertex shouldn't be Vertex and Vertex a should not belong to
> AdditiveGroup
>

Regarding whether vertices and vectors should be treated uniformly, I
particularly would appreciate corrections here. The original file was made
by Emacs keyboard macro when the more sophisticated bits of Template
Haskell failed to be straightforward, so I'm sure there's plenty that one
could do to improve the correctness vs. nearly-blind copypasta :)


> If anyone knows how to walk through the whole module in monad Q that might
> bring more power to this library. I.e. walk through OpenGL.Raw and make
> declarations  for all its scalar types.
>

This, or use of GeneralizedNewtypeDeriving + StandAloneDeriving would be
great to see.


> Thank you
>

Thank you too!

Cheers,
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20120520/a3d28610/attachment.htm>


More information about the Libraries mailing list