mirror of
https://github.com/ilyakooo0/optparse-applicative.git
synced 2024-11-27 11:56:20 +03:00
Add Arrow interface.
This commit is contained in:
parent
62c2de230b
commit
80ea53d20d
33
Options/Applicative/Arrows.hs
Normal file
33
Options/Applicative/Arrows.hs
Normal file
@ -0,0 +1,33 @@
|
||||
module Options.Applicative.Arrows (
|
||||
A(..),
|
||||
asA,
|
||||
runA,
|
||||
ParserA
|
||||
) where
|
||||
|
||||
import Control.Arrow
|
||||
import Control.Category
|
||||
import Options.Applicative
|
||||
|
||||
import Prelude hiding ((.), id)
|
||||
|
||||
newtype A f a b = A
|
||||
{ unA :: f (a -> b) }
|
||||
|
||||
asA :: Applicative f => f a -> A f () a
|
||||
asA x = A $ const <$> x
|
||||
|
||||
runA :: Applicative f => A f () a -> f a
|
||||
runA a = unA a <*> pure ()
|
||||
|
||||
instance Applicative f => Category (A f) where
|
||||
id = A $ pure id
|
||||
-- use reverse composition, because we want effects to run from
|
||||
-- top to bottom in the arrow syntax
|
||||
(A f) . (A g) = A $ flip (.) <$> g <*> f
|
||||
|
||||
instance Applicative f => Arrow (A f) where
|
||||
arr = A . pure
|
||||
first (A f) = A $ first <$> f
|
||||
|
||||
type ParserA = A Parser
|
@ -73,6 +73,7 @@ extra-source-files: README.md
|
||||
|
||||
library
|
||||
exposed-modules: Options.Applicative,
|
||||
Options.Applicative.Arrows,
|
||||
Options.Applicative.Common,
|
||||
Options.Applicative.Types,
|
||||
Options.Applicative.Builder,
|
||||
|
Loading…
Reference in New Issue
Block a user