module Options.Applicative.Arrows (
module Control.Arrow,
A(..),
asA,
runA,
ParserA,
) where
import Control.Arrow
import Control.Category (Category(..))
import Options.Applicative
import Prelude hiding ((.), id)
newtype A f a b = A
{ forall (f :: * -> *) a b. A f a b -> f (a -> b)
unA :: f (a -> b) }
asA :: Applicative f => f a -> A f () a
asA :: forall (f :: * -> *) a. Applicative f => f a -> A f () a
asA f a
x = forall (f :: * -> *) a b. f (a -> b) -> A f a b
A forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> a
const forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
x
runA :: Applicative f => A f () a -> f a
runA :: forall (f :: * -> *) a. Applicative f => A f () a -> f a
runA A f () a
a = forall (f :: * -> *) a b. A f a b -> f (a -> b)
unA A f () a
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
instance Applicative f => Category (A f) where
id :: forall a. A f a a
id = forall (f :: * -> *) a b. f (a -> b) -> A f a b
A forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
(A f (b -> c)
f) . :: forall b c a. A f b c -> A f a b -> A f a c
. (A f (a -> b)
g) = forall (f :: * -> *) a b. f (a -> b) -> A f a b
A forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
(.) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (a -> b)
g forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (b -> c)
f
instance Applicative f => Arrow (A f) where
arr :: forall b c. (b -> c) -> A f b c
arr = forall (f :: * -> *) a b. f (a -> b) -> A f a b
A forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure
first :: forall b c d. A f b c -> A f (b, d) (c, d)
first (A f (b -> c)
f) = forall (f :: * -> *) a b. f (a -> b) -> A f a b
A forall a b. (a -> b) -> a -> b
$ forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (b -> c)
f
type ParserA = A Parser