Functor instances for GetOpt data types

Henning Thielemann lemming at henning-thielemann.de
Sun Nov 20 22:09:27 CET 2011


I propose to add Functor instances for data types in GetOpt as shown 
below. I like to have them since I want to build an Option record from 
sub-records for specific functions, and I like to glue together the 
sub-records and according argument descriptions. With the Functor instance 
I can lift the option descriptions for the sub-records to the main Option 
record.

As an interim solution I could prepare a package that provides these 
instances as orphan instances and has a cabal switch to export the 
instances from base, once they appear there.

Discussion period until 4th of December.


PS: I am scared by the idea to have to compile the whole GHC only in order 
to get 'base' built, and then insert and test these Functor instances. Is 
there an easier way?

PSS: Is it necessary to have GetOpt in base?


----------------------------------

instance Functor ArgOrder where
    fmap f order =
       case order of
          RequireOrder -> RequireOrder
          Permute -> Permute
          ReturnInOrder g -> ReturnInOrder $ f.g

instance Functor ArgDescr where
    fmap f d =
       case d of
          NoArg a -> NoArg $ f a
          ReqArg g str -> ReqArg (f.g) str
          OptArg g str -> OptArg (f.g) str

instance Functor OptDescr where
    fmap f (Option short long arg help) =
       Option short long (fmap f arg) help




More information about the Libraries mailing list