On Mar 8, 2004, at 11:17, Sven Panne wrote:

Hmmm, using generics seems like massive overkill for option handling. Could you
describe what you are exactly trying to achieve?

I am doing command line options parsing. I've defined Flag type with constructor
for each possible option:

data Flag = Verbose |
            Input String  |
            Output String |
            Filter String
            deriving (Show, Typeable, Data)

getOpt returns me a list of such objects. Now I need to
look things up there by constructor. For example:

                ....
                doSomething fltflag
                where
        (Filter fltflag) = findFlag (Filter "none") opts

To achieve this I've defined:

instance Eq Flag where
    x == y = toConstr x == toConstr y

findFlag :: Flag -> [Flag] -> Flag
findFlag f fs = fromMaybe f (find (==f) fs)

Sincerely,
Vadim

--
"La perfection est atteinte non quand il ne reste rien a ajouter, mais
quand il ne reste rien a enlever."  (Antoine de Saint-Exupery)


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to