[Haskell-cafe] CmdArgs non-flag arguments with newtypes

Michael Orlitzky michael at orlitzky.com
Wed Jul 24 03:01:00 CEST 2013


I ran into an issue wrapping a [String] in a newtype with CmdArgs.
You're supposed to be able to declare that a field contains a list of
non-flag arguments... this works fine:

  data Cfg = Cfg { <whatever flags>, usernames :: [String] }
  arg_spec = Cfg { <whatever flags>, usernames = def &= args }
  ...

If I now call my program with,

  ./foo --flag1 --flag2 arg1 arg2

then usernames = [ "arg1", "arg2" ] as desired. However, I need to wrap
usernames in a newtype for an unrelated reason:

  newtype Usernames = Usernames [String]

Now, CmdArgs unexpectedly drops the first non-flag argument. So,

  ./foo --flag1 --flag2 arg1 arg2

gives me usernames = [ "arg2" ]. Obviously not what I want! Has anyone
else run into this? Figured out a workaround?




More information about the Haskell-Cafe mailing list