ndmitchell / cmdargs

Haskell library for command line argument processing
Other
91 stars 12 forks source link

runtime error with newtype declarations #44

Open epsilonhalbe opened 7 years ago

epsilonhalbe commented 7 years ago

Here is a minimal showcase of the error I am facing:

If I declare a newtype datatype - then flags produce runtime errors. For data-declarations everything seems to work just fine.

{-# LANGUAGE DeriveDataTypeable #-}
module Main where

import System.Console.CmdArgs
---------------------------------------------------------------------------------
--                 Newtypes seem to make problems with CMDARGS                 --
---------------------------------------------------------------------------------

newtype NewtypeSample = NewtypeSample {helloNT :: FilePath } deriving (Show, Data, Typeable)

worksNT = NewtypeSample{helloNT = def &= help "World argument" }
         &= summary "NewtypeSample v1"

doesn'tWorkNT1 = NewtypeSample{helloNT = def &= help "World argument" &= opt "world" &= typFile}
         &= summary "NewtypeSample v1"

doesn'tWorkNT2 = NewtypeSample{helloNT = def &= help "World argument" &= opt "world"}
         &= summary "NewtypeSample v1"

---------------------------------------------------------------------------------
--                  Data declarations seem to work just fine                   --
---------------------------------------------------------------------------------

data DataSample = DataSample {helloD :: FilePath } deriving (Show, Data, Typeable)

worksD1 = DataSample{helloD = def &= help "World argument" &= opt "world"}
         &= summary "DataSample v1"

worksD2= DataSample{helloD = def &= help "World argument" &= opt "world" &= typFile}
         &= summary "DataSample v1"

main :: IO ()
main = do 
  print =<< cmdArgs doesn'tWorkNT1
  print =<< cmdArgs doesn'tWorkNT2
  print =<< cmdArgs worksNT
  print =<< cmdArgs worksD1
  print =<< cmdArgs worksD2
  return ()

Here are the errors I get: