Skip to content

Commit

Permalink
Oops, that wasn't a monoid instance...
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorycollins committed Feb 4, 2009
1 parent 449714f commit 057f37d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ data Options = Options {
} deriving (Eq, Show)


defaultOptions = Options { installPrefix = Just "/usr/local"
, showUsage = False
, packageMakerPath = Just "/Developer/usr/bin/packagemaker"
}

instance Monoid Options where
mempty = Options { installPrefix = Just "/usr/local"
mempty = Options { installPrefix = Nothing
, showUsage = False
, packageMakerPath = Just "/Developer/usr/bin/packagemaker"
, packageMakerPath = Nothing
}

a `mappend` b =
Expand All @@ -158,8 +163,8 @@ instance Monoid Options where
, showUsage = showUsage a || showUsage b
}
where
(+) a b = getLast $ (Last a) `mappend` (Last b)
override f = (f a) + (f b)
a *+* b = getLast $ Last a `mappend` Last b
override f = f a *+* f b


------------------------------------------------------------------------
Expand Down Expand Up @@ -213,7 +218,7 @@ getOptions = do
args <- getArgs
opts <-
case GetOpt.getOpt GetOpt.RequireOrder optionFlags args of
(o,n,[]) -> return $ mconcat o
(o,n,[]) -> return $ defaultOptions `mappend` mconcat o
(_,_,errs) -> usage errs

if showUsage opts
Expand Down

0 comments on commit 057f37d

Please sign in to comment.