+ ptoarg [p] [] i = Error ["Not enough arguments for " +++ gfd_name]
+ ptoarg [p:ps] [a:as] i = p a i >>= ptoarg ps as
+ ptoarg [] as i = Ok (i, as)
+gopt{|PAIR|} l r = case (l, r) of
+ (Positionals pl, Positionals pr)
+ = Positionals
+ $ map (combine PFst appPFst) pl
+ ++ map (combine PSnd appPSnd) pr
+ (Flags fl, Flags fr)
+ = Flags
+ $ map (appSnd $ combine` PFst appPFst) fl
+ ++ map (appSnd $ combine` PSnd appPSnd) fr
+where
+ appPFst f (PAIR x y) = PAIR (f x) y
+ appPSnd f (PAIR x y) = PAIR x (f y)
+ PFst (PAIR x y) = x
+ PSnd (PAIR x y) = y
+gopt{|UNIT|} = Positionals []
+gopt{|CONS of {gcd_name}|} c = bifmap (\(CONS a)->a) CONS $ SubParsers [(gcd_name, c)]
+gopt{|EITHER|} l r = case (l, r) of
+ (SubParsers sl, SubParsers sr)
+ = SubParsers
+ $ map (appSnd $ bifmap (\(LEFT a)->a) LEFT) sl
+ ++ map (appSnd $ bifmap (\(RIGHT a)->a) RIGHT) sr
+gopt{|(,)|} l r = case (l, r) of
+ (Positionals pl, Positionals pr)
+ = Positionals
+ $ map (combine fst appFst) pl
+ ++ map (combine snd appSnd) pr
+gopt{|(,,)|} f s t = case (f, s, t) of
+ (Positionals pf, Positionals ps, Positionals pt)
+ = Positionals
+ $ map (combine fst3 appFst3) pf
+ ++ map (combine snd3 appSnd3) ps
+ ++ map (combine thd3 appThd3) pt