Monday, January 18, 2010

data-aviary

Copperbox revision 1094.

I've added a new module to Data-Aviary that specializes operations from Applicative, Monad etc. to the function type. This might be useful for spotting patterns in the type signatures of the operations that might not be obvious in their more general (type-class) type.

For instance to work with records I have a family of 'substs' - extended arity versions of the S (Starling) combinator:



subst :: (r -> a -> b) -> (r -> a) -> r -> b
subst f g x = f x (g x)

subst2 :: (r -> a -> b -> c) -> (r -> a) -> (r -> b) -> r -> c
subst2 f g h x = f x (g x) (h x)

subst3 :: (r -> a -> b -> c -> d) -> (r -> a) -> (r -> b) -> (r -> c) -> r -> d
subst3 f g h i x = f x (g x) (h x) (i x)



Now because I don't use them too often, when I go back to them I'll often think "Oh, they're just liftA2, liftA3" and swap them in the code introducing new type errors everywhere. I tend to forget that liftA2, liftA3 are a family of S' combinators rather than S combinators:


liftA :: (a -> b) -> (r -> a) -> r -> b
liftA2 :: (a -> b -> c) -> (r -> a) -> (r -> b) -> r -> c
liftA3 :: (a -> b -> c -> d) -> (r -> a) -> (r -> b) -> (r -> c) -> r -> d

Blog Archive

About Me

My photo
Disambiguating biog as there are a few Stephen Tetley's in the world. I'm neither a cage fighter or yachtsman. I studied Fine Art in the nineties (foundation Bradford 1992, degree Cheltenham 1992 - 95) then Computing part-time at Leeds Met graduating in 2003. I'm the Stephen Tetley on Haskell Cafe and Stackoverflow.