From 63596a185293f88ca43f51a9446166cd5e7f7ac7 Mon Sep 17 00:00:00 2001 From: sof Date: Fri, 14 Aug 1998 13:16:00 +0000 Subject: [PATCH] [project @ 1998-08-14 13:16:00 by sof] Fixed GetOpt example --- ghc/docs/libraries/libs.sgml | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/ghc/docs/libraries/libs.sgml b/ghc/docs/libraries/libs.sgml index 4a693ec..f909c59 100644 --- a/ghc/docs/libraries/libs.sgml +++ b/ghc/docs/libraries/libs.sgml @@ -625,7 +625,7 @@ data ForeignObj -- abstract, instance of: Eq makeForeignObj :: Addr{-object-} -> Addr{-finaliser-} -> IO ForeignObj writeForeignObj :: ForeignObj -> Addr{-new value-} -> IO () -data StablePtr a +data StablePtr a -- abstract, instance of: Eq. makeStablePtr :: a -> IO (StablePtr a) deRefStablePtr :: StablePtr a -> IO a freeStablePtr :: StablePtr a -> IO () @@ -811,7 +811,7 @@ which might be used to build an ordered binary tree, say. The Would this constraint be +constructor is never duplicated. Provided you follow the +the author of Would this constraint be unworkable in practice?] Both +module Opts where + +import GetOpt +import Maybe ( fromMaybe ) + data Flag = Verbose | Version - | Input String | Output String + | 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 out "FILE") "output FILE" - , Option ['c'] [] (OptArg in "FILE") "input FILE" + , Option ['o'] ["output"] (OptArg outp "FILE") "output FILE" + , Option ['c'] [] (OptArg inp "FILE") "input FILE" + , Option ['L'] ["libdir"] (ReqArg LibDir "DIR") "library directory" ] -out :: Maybe String -> Flag -out Nothing = Output "stdout" -out (Just of) = Output of - -in :: Maybe String -> Flag -in Nothing = Input "stdin" -in (Just i) = Input i +inp,outp :: Maybe String -> Flag +outp = Output . fromMaybe "stdout" +inp = Input . fromMaybe "stdout" -compilerOpts :: [String] -> IO (String, String) +compilerOpts :: [String] -> IO ([Flag], [String]) compilerOpts argv = - case (getOpt NoOrder options argv) of + 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..." -- 1.7.10.4