haskell - converting list to tuple -
i have few command-line options (5 example) , want convert them tuple. problem expect them appear in correct order, tuple can built list using pattern-match, in real life options can provided in random order, don't know if head of list contain verbose option or log file name?
i tried think how using continuation-passing style, nothing useful comes mind.
is ever possible?
i think can "sort" list have in predicted order, not good.
also rid of tuple , create data record - still lead checking type of attribute , set correct field of record. still lot of typing.
given describe, think have 2 options. of two, converting dictionary easiest, converting tuple work , little clumsy
so, take definition:
options :: [optdescr (string, string)] options = [option ['a'] ["alpha"] (reqarg (\a -> ("alpha", a)) "empty") "", option ['b'] ["beta"] (reqarg (\a -> ("beta", a)) "empty") "", option ['g'] ["gamma"] (reqarg (\a -> ("gamma", a)) "empty") ""] main = args <- getargs let (opts, nonopts, errs) = getopt permute options args putstrln $ show opts  from this, couple of example outputs are:
[("beta","b"),("alpha","a")] [("alpha","a"),("gamma","g"),("beta","b")]  and on. same order on command line. but, because of way set above, have association list, so... if in particular want tuple has values (alpha, beta, gamma), best option is...
(lookup "alpha" opts, lookup "beta" opts, lookup "gamma" opts)  you resulting data type (maybe string, maybe string, maybe string), in order of "alpha", "beta", , "gamma".
Comments
Post a Comment