[Haskell-cafe] Systematic treatment of static arguments
Stephen Tetley
stephen.tetley at gmail.com
Sat Oct 16 15:39:34 EDT 2010
Hello list
The Monad and Applicative instances for functions are "equivalent" to
the respective Reader vesions (I use "equivalent" along the lines of -
operationally the same but without the type distinction / newtype).
There is also the Monoid instance for functions which is pretty slick.
Has anyone looked at variations with two or more static arguments though?
For example mappend with two static arguments needs to be defined
either as a new function:
> mappendR2 :: Monoid a => (r1 -> r2 -> a) -> (r1 -> r2 -> a) -> r1 -> r2 -> a
> mappendR2 f g = \x y -> f x y `mappend` g x y
or an overlapping instance:
> instance Monoid a => OPlus (r1 -> r2 -> a) where
> f `mappend` g = \x y -> f x y `mappend` g x y
Working in graphics I've found two static arguments comes up quite
often - preliminarily most of my functions are functions from the
DrawingContext to something (drawing context is an environment that
tracks line width, stroke colour, fill colour, etc.):
fn1 :: DrawingCtx -> a
Many of my functions statically use a 'start' point as the only
coordinate reference, so they are in a "coordinate free" style:
fn2 :: Point -> DrawingCtx -> a
Some functions even have have a third static argument, for example
drawing arrowheads for lines seems nice if the angle of the line is
parametric and not used explicitly:
fn3 :: Radian -> Point -> DrawingCtx -> a
The help from Applicative, Monad and Monoid is "used up" by the one
static argument version, so I find that I have to introduce points (in
the pointed / point-free sense not in the graphic sense) in the fn2
and fn3 versions where a point-free version might still be nice.
Is there any prior work looking at sets of combinators for these
higher arity functions - papers or code? I'd prefer not to introduce a
whole new lexicon of combinator names if I can help it.
Thanks
Stephen
More information about the Haskell-Cafe
mailing list