Created
October 19, 2010 22:07
-
-
Save ghulette/635236 to your computer and use it in GitHub Desktop.
Product category (sort of)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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