12 Dec 19:01
newtypes and optimization
From: Scott Dillard <sedillard <at> gmail.com>
Subject: newtypes and optimization
Newsgroups: gmane.comp.lang.haskell.glasgow.user
Date: 2007-12-12 18:02:15 GMT
Subject: newtypes and optimization
Newsgroups: gmane.comp.lang.haskell.glasgow.user
Date: 2007-12-12 18:02:15 GMT
Hi,
I have a statically-sized-list library that I use for linear algebra stuff.
It's got a vector type something like this:
> data V a b = V a b
so that a 3D vector is
> type Vec3 a = V a (V a (V a ()))
and I have type classes for operations on these things, like so:
> class VZipWith a b c u v w | {-lots of fundeps-} where
> vzipWith :: (a -> b -> c) -> u -> v -> w
>
> instance VZipWith a b c (V a ()) (V b ()) (V c ()) where
> vzipWith f (V x ()) (V y ()) = V (f x y) ()
>
> instance
> VZipWith a b c (V a u) (V b v) (V c w)
> => VZipWith a b c (V a (V a u)) (V b (V b v)) (V c (V c w))
> where
> vzipWith f (V x u) (V y v) = V (f x y) (vzipWith f u v)
so that vector addition is
> vadd = vzipWith (+)
I put strictness annotations and INLINE pragmas all over the place, and GHC
(Continue reading)
RSS Feed