[Haskell-cafe] More experiments with ATs
Stephen Tetley
stephen.tetley at gmail.com
Sat Jul 3 11:39:26 EDT 2010
Hello Andrew
The non-type-changing map is sometimes useful as a type class - in my
graphics lib Wumpus, I call it pointwise:
class Pointwise sh where
type Pt sh :: *
pointwise :: (Pt sh -> Pt sh) -> sh -> sh
For the graphics I want objects to be parametric on unit (which is
usually Double), i.e.:
data Point2 u = P2 !u !u
But I usually don't want to deeply map on the unit, for instance a
bounding box is represented as two corner points, bottom-left and
top-right - for affine transformations I want to map on the points
rather than the unit-of-points, so the Pointwise instance is:
instance Pointwise (BoundingBox u) where
type Pt (BoundingBox u) = Point2 u
pointwise f (BBox bl tr) = BBox (f bl) (f tr)
Where Bounding Box is:
data BoundingBox u = BBox
{ ll_corner :: Point2 u
, ur_corner :: Point2 u
}
I've seen this typeclass appear on the Cafe a couple of times under
different names of course.
More information about the Haskell-Cafe
mailing list