
First off, let me apologize for this ongoing series of stupid newbie questions. Haskell just recently went from that theoretically interesting language I really need to learn some day to a language I actually kinda understand and can write real code in (thanks to Real World Haskell). Of course, this gives rise to a whole bunch of "wait- why is it this way?" sort of questions. So today's question is: why isn't there a Strict monad? Something like: data Strict a = X a instance Monad Strict where ( >>= ) (X m) f = let x = f m in x `seq` (X x) return a = a `seq` (X a) (although this code doesn't compile for reasons I'm not clear on- I keep getting: temp.hs:4:0: Occurs check: cannot construct the infinite type: b = Strict b When trying to generalise the type inferred for `>>=' Signature type: forall a b1. Strict a -> (a -> Strict b1) -> Strict b1 Type to generalise: forall a b1. Strict a -> (a -> Strict b1) -> Strict b1 In the instance declaration for `Monad Strict' as a type error. Feel free to jump in and tell me what I'm doing wrong.) Obviously, there would also be a StrictT monad transformer. The point here is that there are some monads (State being the obvious one) that come in both strict and lazy variants- the two variants could be eliminated, and the strict variant would just become a StrictT (State x) a. Or maybe a StateT x Strict a. Hmm. Which raises the interesting question of what, if any, semantic difference there is between a StrictT (State x) a and a StateT x Strict a. In any case, the idea came when I was thinking about monads being "code regions"- that we can talk about such and such a function being "in" the IO monad or STM monad. The idea was that one could define a "strict" code region you could put code in. Brian