[Haskell-cafe] Taking Exception to Exceptions

Immanuel Litzroth immanuel203 at gmail.com
Thu Jan 8 10:37:11 EST 2009


>
>
> I recommend this paper for info, it's very easy to follow:
>
> http://www.haskell.org/~simonmar/papers/ext-exceptions.pdf<http://www.haskell.org/%7Esimonmar/papers/ext-exceptions.pdf>
>
> Austin
>
That paper cleared up most of my issues and it is amazing that it is
not amongst the papers that are referenced at the top of the the page
describing Control.Exception.
Anyway, there is one more problem I have related to exceptions that is
about forcing strictness. It relates to option parsing. I have an option -t
that says which track from a file of tracks to print. So I go

data Flags = TrackNumber !Int deriving(Read, Show, Eq)

makeTrackNumber :: String -> Flags
makeTrackNumber str =
    TrackNumber $ read str

options = [GetOpt.Option ['t'] ["tracknumber"] (GetOpt.ReqArg
makeTrackNumber "tracknumber") "number of track to show"]

Now my main goes
main = do
  args <- getArgs
  opts <- evaluate $ GetOpt.getOpt GetOpt.RequireOrder options args
  print "done getting the opts"
  case opts of ...

which of course first prints "done getting opts" and then throws an
exception if I give it a flag
-t abc. What would be the way to proceed here? Do I increase the strictness
or do I write a handler
around my complete main? Even if I map the exception in makeTrackNumber to
my very own
exception how do I find out which exact call gave a problem i.e. which is
the call stack at the moment
the exception was thrown -- I might use makeTrackNumber in other contexts
too.
Thanks in advance,
Immanuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090108/50349221/attachment.htm


More information about the Haskell-Cafe mailing list