On Wed, Sep 19, 2001 at 01:53:22PM -0400, Mark Carroll wrote:
>
> main = let maybe_index = maybe_read word
> in putStr (show (if maybe_index == Nothing then DP_Unknown else DP_Number
>index) ++ "\n")
> where (Just index) = maybe_index
>
> BTW, is the above a sane way of getting the 'index' 'out of' the "Just"?
> I often seem to be using a "where (Just foo) = bar" type of idiom.
I'd probably write this as something like
main = case maybe_read word of
Just index -> putStrLn $ show $ if maybe_index == Nothing
then DP_Unknown
else DP_Number index
Nothing -> error "No index found"
As for let versus where, I use whatever I think looks best, which tends
to be where unless I have lots of nested ifs and cases.
Ian
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe