Skip to content

Instantly share code, notes, and snippets.

@ghulette
Created October 19, 2010 22:07
Show Gist options
  • Save ghulette/635236 to your computer and use it in GitHub Desktop.
Save ghulette/635236 to your computer and use it in GitHub Desktop.
Product category (sort of)
-- Product category instance
import Prelude hiding ((.),id)
import Control.Category
data Product c d x y = Product (c x y) (d x y)
deriving (Eq,Show)
instance (Category c,Category d) => Category (Product c d) where
id = Product id id
(Product e f).(Product g h) = Product (e.g) (f.h)
app :: Product (->) (->) a b -> (a,a) -> (b,b)
app (Product f g) (x,y) = (f x,g y)
main :: IO ()
main = do
let f = (+1)
let g = (*2)
let gfxfg = Product f g >>> Product g f
print $ app gfxfg (3,4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment