Haskell, cmdargs and newtypes
I have the following snippet, which compiles fine, but when I try to run it I get an error from cmdargs. *** Exception: 开发者_JAVA技巧System.Console.CmdArgs.Implicit, unexpected flag (edit): Main.Sel
. It works if I change the Sel to Int, but in my real use case I'd like to have type enforcement that differentiates selections from Ints.
I can fix it by using Int with cmdargs and after checking the arguments casting it to Sel, but I think this is suboptimal solution.
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
import System.Console.CmdArgs
import System.Console.CmdArgs.Default
newtype Sel = Sel Int deriving (Num, Real, Integral, Show, Read, Data, Typeable, Enum, Eq, Ord, Default)
data Foo = Foo {
edit :: Sel
} deriving (Show, Read, Data, Typeable)
foo = Foo {
edit = def
}
main = do
a <- cmdArgs foo
print a
It is suboptimal indeed, and I've raised a bug to track the addition of this feature: http://code.google.com/p/ndmitchell/issues/detail?id=422
I might have time to work on it this weekend, it shouldn't be too hard (but depends how much further than newtypes I want to go). (For context, I wrote cmdargs)
Update: I just released cmdargs 0.6.9 on Hackage which supports newtypes as requested in this question.
精彩评论