nilcons / hflags Goto Github PK
View Code? Open in Web Editor NEWCommand line flag parser for Haskell, conceptually very similar to Google's gflags
License: Apache License 2.0
Command line flag parser for Haskell, conceptually very similar to Google's gflags
License: Apache License 2.0
I get the following error when compiling with GHC 8.0.1 release:
Preprocessing library hflags-0.4.1...
[1 of 1] Compiling HFlags ( HFlags.hs, dist/build/HFlags.o )
HFlags.hs:406:42: error:
• Ambiguous type variable ‘b0’ arising from a use of ‘show’
prevents the constraint ‘(Show b0)’ from being solved.
Relevant bindings include
dupe :: [(b0, [Char])] (bound at HFlags.hs:405:6)
Probable fix: use a type annotation to specify what ‘b0’ should be.
These potential instances exist:
instance Show NestedAtomically
-- Defined in ‘Control.Exception.Base’
instance Show NoMethodError -- Defined in ‘Control.Exception.Base’
instance Show NonTermination -- Defined in ‘Control.Exception.Base’
...plus 97 others
...plus 88 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the second argument of ‘(++)’, namely ‘(show $ map fst dupe)’
In the second argument of ‘(++)’, namely
‘", modules: " ++ (show $ map fst dupe)’
In the second argument of ‘(++)’, namely
‘(snd $ head dupe) ++ ", modules: " ++ (show $ map fst dupe)’
HFlags.hs:409:27: error:
• The constructor ‘InstanceD’ should have 4 arguments, but has been given 3
• In the pattern: InstanceD _ (AppT _ inst) _
In an equation for ‘instanceToFlagData’:
instanceToFlagData (InstanceD _ (AppT _ inst) _)
= [| getFlagData (undefined :: $(return inst)) |]
pending(rn) [<splice, return inst>]
In an equation for ‘getFlagsData’:
getFlagsData
= do { ClassI _ instances <- reify ''Flag;
case dupes instances of {
[] -> return ()
(dupe : _)
-> fail
("Multiple definition of flag "
++ (snd $ head dupe) ++ ", modules: " ++ (show $ map fst dupe)) };
listE $ map instanceToFlagData instances }
where
instanceToFlagData (InstanceD _ (AppT _ inst) _)
= [| getFlagData (undefined :: $(return inst)) |]
pending(rn) [<splice, return inst>]
instanceToFlagData _ = error "Shouldn't happen"
instanceToModuleNamePair (InstanceD _ (AppT _ (ConT inst)) _)
= let ... in (modName, flag)
instanceToModuleNamePair _ = error "Shouldn't happen"
dupes instances
= filter ((> 1) . length)
$ groupBy ((==) `on` snd)
$ sortBy (compare `on` snd)
$ map instanceToModuleNamePair instances
HFlags.hs:415:33: error:
• The constructor ‘InstanceD’ should have 4 arguments, but has been given 3
• In the pattern: InstanceD _ (AppT _ (ConT inst)) _
In an equation for ‘instanceToModuleNamePair’:
instanceToModuleNamePair (InstanceD _ (AppT _ (ConT inst)) _)
= let
(flagrev, modrev) = span (/= '.') $ reverse $ show inst
modName = reverse $ drop 1 modrev
....
in (modName, flag)
In an equation for ‘getFlagsData’:
getFlagsData
= do { ClassI _ instances <- reify ''Flag;
case dupes instances of {
[] -> return ()
(dupe : _)
-> fail
("Multiple definition of flag "
++ (snd $ head dupe) ++ ", modules: " ++ (show $ map fst dupe)) };
listE $ map instanceToFlagData instances }
where
instanceToFlagData (InstanceD _ (AppT _ inst) _)
= [| getFlagData (undefined :: $(return inst)) |]
pending(rn) [<splice, return inst>]
instanceToFlagData _ = error "Shouldn't happen"
instanceToModuleNamePair (InstanceD _ (AppT _ (ConT inst)) _)
= let ... in (modName, flag)
instanceToModuleNamePair _ = error "Shouldn't happen"
dupes instances
= filter ((> 1) . length)
$ groupBy ((==) `on` snd)
$ sortBy (compare `on` snd)
$ map instanceToModuleNamePair instances
When I try to run SimpleExample.hs I get the error:
Not in scope: 'HFlags.arguments'
I am running ghc 7.4.1
so the user can conveniently ignore arguments without "Warning: A do-notation statement discarded a result of type [String]."
I suppose the license for this package should be Apache-2.0
instead of OtherLicense
.
I'm new to Haskell and am using hflags to parse command line options in my project.
Can you tell me what would be the best way to handle non-flag arguments using this module.
For example:
On typing the following command
hello --print --debug file.txt file2.txt
I want print
and debug
to appear as variables (which hflags does) and simultaneously [file.txt : file2.txt]
to appear in a list
Is it possible to get
--favorite_color=COLOR Your favorite color. (default: Yellow)
instead of
--favorite_color=COLOR Your favorite color. (default: Yellow, from module: Main)
?
i prefer to have code depending on the environment marked as such. i usually use IO
for that.
can one, additionally to flags_flagN :: a
generate a ioFlags_flagN :: IO a
or similar (maybe with MonadIO constraint)
. that way i'd feel more confident when using it as i only would have to remember always using the right function and the types will work everything out for me.
Trying to compile with latest GHC 8 release candidate leads to the following error:
HFlags.hs:188:17: error:
• Couldn't match expected type ‘Q Dec’
with actual type ‘CxtQ -> DecQ’
• Probable cause: ‘dataD’ is applied to too few arguments
In a stmt of a 'do' block:
dataDec <- dataD
(cxt []) dataName [] [normalC dataConstrName []] []
In the expression:
do { (name, short) <- if
| length name' == 0
-> fail "Flag's without names are not supported."
| length name' == 1 -> return (name', Just $ head name')
| length name' == 2 -> return (name', Nothing)
| name' !! 1 == ':' -> return (drop 2 name', Just $ head name')
| otherwise -> return (name', Nothing);
defE <- defQ;
flagType <- case defE of {
SigE _ flagType -> return $ return flagType
_ -> fail
"Default value for defineCustomFlag has to be an explicitly typed expression, like (12 :: Int)" };
moduleName <- fmap loc_module location;
.... }
In an equation for ‘defineCustomFlag’:
defineCustomFlag name' defQ argHelp readQ showQ description
= do { (name, short) <- if
| length name' == 0
-> fail "Flag's without names are not supported."
| length name' == 1 -> return ...
| length name' == 2 -> return ...
| name' !! 1 == ':' -> return ...
| otherwise -> return ...;
defE <- defQ;
flagType <- case defE of {
SigE _ flagType -> return $ return flagType
_ -> fail
"Default value for defineCustomFlag has to be an explicitly typed expression, like (12 :: Int)" };
.... }
HFlags.hs:188:44: error:
• Couldn't match expected type ‘Maybe Kind’
with actual type ‘[ConQ]’
• In the fourth argument of ‘dataD’, namely
‘[normalC dataConstrName []]’
In a stmt of a 'do' block:
dataDec <- dataD
(cxt []) dataName [] [normalC dataConstrName []] []
In the expression:
do { (name, short) <- if
| length name' == 0
-> fail "Flag's without names are not supported."
| length name' == 1 -> return (name', Just $ head name')
| length name' == 2 -> return (name', Nothing)
| name' !! 1 == ':' -> return (drop 2 name', Just $ head name')
| otherwise -> return (name', Nothing);
defE <- defQ;
flagType <- case defE of {
SigE _ flagType -> return $ return flagType
_ -> fail
"Default value for defineCustomFlag has to be an explicitly typed expression, like (12 :: Int)" };
moduleName <- fmap loc_module location;
.... }
Looks like Template Haskell type of dataD
got a new argument CxtQ
.
Would it be possible to upgrade this one?
Trying to hflags with GHC 8.2.1, I get the following error:
Preprocessing library for hflags-0.4.2..
Building library for hflags-0.4.2..
[1 of 1] Compiling HFlags ( HFlags.hs, dist/build/HFlags.o )
HFlags.hs:190:81: error:
• Couldn't match type ‘Q Cxt’ with ‘[DerivClauseQ]’
Expected type: [DerivClauseQ]
Actual type: CxtQ
• In the sixth argument of ‘dataD’, namely ‘(cxt [])’
In a stmt of a 'do' block:
dataDec <- dataD
(cxt []) dataName [] Nothing [normalC dataConstrName []] (cxt [])
In the expression:
do (name, short) <- if | length name' == 0
-> fail "Flag's without names are not supported."
| length name' == 1 -> return (name', Just $ head name')
| length name' == 2 -> return (name', Nothing)
| name' !! 1 == ':' -> return (drop 2 name', Just $ head name')
| otherwise -> return (name', Nothing)
defE <- defQ
flagType <- case defE of
SigE _ flagType -> return $ return flagType
_ -> fail
"Default value for defineCustomFlag has to be an explicitly typed expression, like (12 :: Int)"
moduleName <- fmap loc_module location
....
|
190 | dataDec <- dataD (cxt []) dataName [] Nothing [normalC dataConstrName []] (cxt [])
| ^^^^^^
Hi. I am attempting to use HFlags and only one of the two flags being defined actually is recognized:
{-# LANGUAGE TemplateHaskell #-}
import HFlags
defineFlag "x" (0.5 :: Double) "x"
defineFlag "y" (1 :: Int) "y"
main = do
s <- $initHFlags "Testcase"
print flags_y
This results in a runtime error, "Flag y not found at runtime, look into HFlags-source/examples/package/Tup.hs. Sorry." The "x" flag seems to work fine, it's the "y" flag that doesn't.
This is HFlags-4.0, GHC 7.8.2, on OS X. Perhaps I am doing something wrong?
hi,
i have not used hflags in the real world yet, so i certainly might have missed it, but i can't find a solution to my problems looking at the api.
i often need to interact with environment variables that can also be set as cmdline arguments. i think it's an implementation detail, that hflags is parsing the arguments, so i'd like to either (more flexible) specify the name of the environment variable to consider or remove/change the HFLAGS_
prefix.
(i also don't like that environment variables are not all uppercase, but that's a side remark only. as is, that it's not clearly stated, whether the cmdline arguments or the environment takes precedence.)
Documentation should explicitly state that cmdline flags overwrite any values set by environment variables.
with ghc 7.8.4, a dummy defineFlag (or a return []) is needed.
Seems the same issue as http://hackage.haskell.org/package/QuickCheck-2.7.6/docs/Test-QuickCheck-All.html#v:quickCheckAll
Test case:
{-# LANGUAGE TemplateHaskell #-}
module Main where
import HFlags
defineFlag "f" True "A flag."
return []
--defineFlag "g" True "Another flag."
main = do
_ <- $initHFlags "flags demo"
print Main.flags_f
Without the return [] or the commented out flag definition, accessing Main.flags_f results in a runtime error.
I don't know enough of TH to decide whether it is a ghc bug (it looks like it), but even if it is a ghc problem, mentioning the workaround as quickcheck does would be good. I'd never have figured this out without help from mailing lists.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.