[Haskell-cafe] How to understand such a `case` ?
daniel.is.fischer at web.de
Tue Dec 8 20:35:32 EST 2009
Am Mittwoch 09 Dezember 2009 01:59:21 schrieb zaxis:
> findHelper (x:xs) = do -- not lazy, but that's not really important here
> filex <- fileExists (file x)
> filex' <- fileExists (file' x)
> case () of
> | filex -> return $ Just $ file x
> | filex' -> return $ Just $ file' x
> | otherwise -> findHelper xs
Such a 'case' is a typographically more pleasant way to test multiple alternatives than a
nested if-then-else chain.
With an if-then-else chain, the code would wander to the right and be less easily
followed. Using a
case () of
_ | condition1 -> thing1
| condition2 -> thing2
| condition3 -> thing3
you can nicely align all possibilities. Since the 'case' here is extraneous to the code
logic and serves only aesthetic ends, such a practice may be frowned upon.
> file x = foldl1 joinFileName (x ++ [helper])
> file' x = (file x) ++ (getConfig "exe_ext")
More information about the Haskell-Cafe