2
我有下面的代碼片段,它編譯得很好,但是當我嘗試運行它時,我從cmdargs中得到一個錯誤。 *** Exception: System.Console.CmdArgs.Implicit, unexpected flag (edit): Main.Sel
。如果我將Sel更改爲Int,它會起作用,但在我真正的用例中,我希望具有類型強制,以區分Ints的選擇。Haskell,cmdargs和newtypes
我可以通過在cmdargs中使用Int並檢查將其轉換爲Sel後的參數來解決此問題,但我認爲這是次優解決方案。
{-# 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