[Haskell] Mixing monadic and non-monadic functions

Iavor S. Diatchki diatchki at cse.ogi.edu
Tue Mar 23 10:34:20 EST 2004


hi,
at some level you are right that some more syntactic sugar
and stuff could make monads more atracitve. for the time
being here is how i'd write what you want bellow:

f # m           = liftM f m
mx === my  = liftM2 (==) m1 m2

assertBool "fail" $ (length # someFunc a) === (length # someFunc b)

at the moment we only have syntactic sugar for working with the list monad
(list comprehensions etc), and environemnt (aka reader) monad (implicit 
parameters).

hope this helps
-iavor

Sean E. Russell wrote:

>Hello,
>
>I posted this question to comp.lang.functional, and someone suggested that I 
>try this group instead.
>
>I'm struggling with monads.  Well, not monads themselves, but mixing them with 
>non-monadic functions.
>
>Here's my base case:
>
>	someFunc :: String -> IO [a]
>	...
>		ax <- someFunc a
>		bx <- someFunc b
>		assertBool "fail" $ length ax == length bx
>
>I don't like the assignments; the typing is redundant, if I have a lot of 
>asserts like this, and the "variables" are temporary.  What I'd much rather 
>have is:
>
>	...
>		assertBool "fail" $ (length $ someFunc a) == (length $ someFunc b)
>
>which is more readable, to my eye.
>
>The only solution which has been suggested that may work is liberal use of the 
>liftM variants, but this gets *really* tedious and obtuse.
>
>Is there an elegant way to do what I want to do, or am I stuck with 
>procedural-style assignments and bunches of temp vars?
>
>Thanks!
>
>  
>



More information about the Haskell mailing list