Created
May 17, 2011 08:07
-
-
Save sordina/976136 to your computer and use it in GitHub Desktop.
How many arrow laws am I breaking?
This file contains hidden or 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
{-# Language TypeOperators #-} | |
import Prelude hiding ((.), id) | |
import Control.Arrow | |
import Control.Category | |
{- | |
> let math = ("add 2" :-: (+2)) . ("times 3" :-: (*3)) >>> ("invert" :-: (1/)) | |
> math | |
(invert) . ((add 2) . (times 3)) | |
> runFun math 9 | |
3.4482758620689655e-2 | |
-} | |
data (:->:) a b = String :-: (a -> b) | |
runFun :: (a :->: b) -> a -> b | |
runFun (_ :-: f) a = f a | |
instance Category (:->:) where | |
id = "id" :-: id | |
(s1 :-: f1) . (s2 :-: f2) = ("(" ++ s1 ++ ") . (" ++ s2 ++ ")") :-: (f1 . f2) | |
instance Show (a:->:b) where | |
show (s :-: _) = s | |
instance Arrow (:->:) where | |
arr f = "Lambda" :-: f | |
first lf@(s :-: f) = ("first (" ++ show lf ++ ")") :-: (\(b, d) -> (f b, d)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess I would have to override
(&&&)
and(***)
for the actual arrow behaviour to be meaningful...This is mainly a Control.Category exercise :D