Sengan Baring-Gould writes: >Is >>= not lazy? since no experts have answered yet, this newbie will answer. I think it's strict. Well, it depends. (>>=) is an overloaded operator, with a different implementation for every monad -- when you define a monad, you give the implementation of (>>=). If your implementation is strict (presumably in the first operand), then (>>=) is strict *at that type*. If your implementation is lazy, then it isn't. The same goes for (+): at most types (+) is strict, but if you define your own kind of number with a lazy addition, then on that type (+) will be lazy. For many monads, (>>=) *is* strict, which fits with the intuition that it is a `sequencing' operator. But by no means for all. The simplest counter-example is the identity monad: newtype Id a = Id a instance Monad Id where return = Id Id x >>= f = f x where m>>=f is strict in m only if f is a strict function. A more interesting example is the state transformer monad: newtype ST s a = ST (s -> (a,s)) instance Monad (ST s) where return x = ST (\s -> (x,s)) ST h >>= f = ST (\s -> let (a,s') = h s ST h' = f a in h' s') where once again, the implementation of (>>=) is strict only if f is a strict function. Hence `lazy state' makes sense! John Hughes
Are there any Haskell libraries or programs related to group theory? I am taking a class and it seems like Haskell would be a good programming language for exploring/reasoning about group theory. What I had in mind was perhaps you could have a function which takes a list(set) and a function with two arguments(binary operator) and checks to see whether or not it is a group. I think it might be a fun exercies to write myself but I'd like to see if it's already been done or what you guys think about it. Eric Wohlstadter UCDavis Software Engineering
Eric Allen Wohlstadter (wohlstad@cs.ucdavis.edu) wrote: : Are there any Haskell libraries or programs related to group theory? I am : taking a class and it seems like Haskell would be a good programming : language for exploring/reasoning about group theory. What I had in mind : was perhaps you could have a function which takes a list(set) and a : function with two arguments(binary operator) and checks to see whether or : not it is a group. I think it might be a fun exercies to write myself but : I'd like to see if it's already been done or what you guys think about it. I think Sergey Mechveliani's docon (algebraic DOmain CONstructor) has facilities for that. Have a look at: http://www.cs.bell-labs.com/who/wadler/realworld/docon.html Regards, Marc van Dongen
participants (3)
-
Eric Allen Wohlstadter -
John Hughes -
Marc van Dongen