
8 Mar
2004
8 Mar
'04
8:55 p.m.
On Mon, 8 Mar 2004, Vadim Zaliva wrote:
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
Try this instead: doSomething $ option "none" [fltflag | Filter fltflag <- opts] ... option :: a -> [a] -> a option def [] = def option def [x] = x option def _ = error "Only one of each option allowed" -- Ben