[Haskell] Mixing monadic and non-monadic functions
Max Kirillov
max630 at mail.ru
Wed Mar 24 09:03:17 EST 2004
On Tue, Mar 23, 2004 at 10:29:26AM -0500, Sean E. Russell wrote:
> Here's my base case:
>
> someFunc :: String -> IO [a]
> ...
> ax <- someFunc a
> bx <- someFunc b
> assertBool "fail" $ length ax == length bx
>
> <...>What I'd much rather have is:
>
> ...
> assertBool "fail" $ (length $ someFunc a) == (length $ someFunc b)
>
> which is more readable, to my eye.
Monads are not just a fascistic typing feture. They are to ensure the
order of actions. Your first version makes clear (and makes sure)
that 'someFunc a' is executed before 'someFunc b'. The second does not.
If you don't need that, maybe you should inspect why your someFunc has
type '.. -> IO ..'. Usually that means that it involves some IO, so
you may not ignore the order of actions.
--
Max
More information about the Haskell
mailing list