On NT4.0 sp3, ghc 5.01 thrill-seeker's release, I get the following
compile error when trying to build the example snippet at the end of
the GetOpt section in the manual. I've also included the code, in case
it's changed from the version I have...
---
Administrator at BRK /NextGen/src/magellan/src/haskell
$ ghc -package util scratch.hs
scratch.hs:28:
Couldn't match `String' against `IOError'
Expected type: String
Inferred type: IOError
In the application `userError ((concat errs)
++ (usageInfo header options))'
In the first argument of `fail', namely
`(userError ((concat errs) ++ (usageInfo header options)))'
Administrator at BRK /NextGen/src/magellan/src/haskell
$
---
module Opts where
import GetOpt
import Maybe ( fromMaybe )
data Flag
= Verbose | Version
| Input String | Output String | LibDir String
deriving Show
options :: [OptDescr Flag]
options =
[ Option ['v'] ["verbose"] (NoArg Verbose) "chatty output on
stderr"
, Option ['V','?'] ["version"] (NoArg Version) "show version number"
, Option ['o'] ["output"] (OptArg outp "FILE") "output FILE"
, Option ['c'] [] (OptArg inp "FILE") "input FILE"
, Option ['L'] ["libdir"] (ReqArg LibDir "DIR") "library directory"
]
inp,outp :: Maybe String -> Flag
outp = Output . fromMaybe "stdout"
inp = Input . fromMaybe "stdout"
compilerOpts :: [String] -> IO ([Flag], [String])
compilerOpts argv =
case (getOpt Permute options argv) of
(o,n,[] ) -> return (o,n)
(_,_,errs) -> fail (userError (concat errs ++ usageInfo header
options))
where header = "Usage: ic [OPTION...] files..."