Skip to content

Instantly share code, notes, and snippets.

@scan
Created July 23, 2012 19:57
Show Gist options
  • Save scan/3165838 to your computer and use it in GitHub Desktop.
Save scan/3165838 to your computer and use it in GitHub Desktop.
module Main where
import Prelude hiding (id, (.))
import Control.Category
import Control.Arrow
newtype Auto b c = Auto (b -> (c, Auto b c))
instance Category Auto where
id = Auto $ \a -> (a, id)
(Auto a) . (Auto b) = Auto $ \c ->
let (c1, f1) = b c
(c2, f2) = a c1 in
(c2, f2 . f1)
instance Arrow Auto where
arr f = Auto $ \a -> (f a, arr f)
first (Auto f) = Auto $ \(a, b) -> let (c, f') = f a in ((c, b), first f')
instance ArrowLoop Auto where
loop (Auto f) = Auto $ \a -> let ((c, d), f') = f (a, d) in (c, loop f')
instance ArrowChoice Auto where
left (Auto f) = Auto left'
where
left' (Left b) = let (c, f') = f b in ((Left c), left f')
left' (Right d) = ((Right d), arr $ \_ -> Right d)
instance ArrowApply Auto where
app = Auto $ \((Auto f), b) -> (fst . f $ b, app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment