#1127: Make mtl lazier
-------------------------------+--------------------------------------------
 Reporter:  igloo              |          Owner:         
     Type:  proposal           |         Status:  closed 
 Priority:  normal             |      Milestone:  Not GHC
Component:  libraries (other)  |        Version:  6.6    
 Severity:  normal             |     Resolution:  fixed  
 Keywords:                     |     Difficulty:  Unknown
 Testcase:                     |   Architecture:  Unknown
       Os:  Unknown            |  
-------------------------------+--------------------------------------------
Changes (by igloo):

  * resolution:  => fixed
  * status:  new => closed

Comment:

 While this started off as just making StateT lazy, it has ultimately ended
 up as a much larger rejig of the mtl library. The patch description is:
 {{{
 Sat Mar  3 15:22:21 GMT 2007  Ian Lynagh <[EMAIL PROTECTED]>
   * Rejig mtl; trac proposal #1127
     Moved the MonadFoo classes to Control.Monad.Foo.Class.

     Put the instances consistently in the module which defines the type
 they
     give an instance for.

     Made the existing transformers lazy to match the existing monads, and
 put
     them in Control.Monad.Foo.Lazy. Also added Control.Monad.Foo.Strict
 with
     strict monads and transformers. Control.Monad.Foo still exports what
 it
     used to.

     Created a MonadRWS class.

     Made the MonadWriter w (ErrorT e m) instance strict to match
 everything
     else.
 }}}

 Neil Mitchell advocated State and State' rather than State.Lazy and
 State.Strict but there seemed to be a concensus for the latter (also used
 by some modules in the base package).

 Don Stewart asked for an example showing the different behaviours, to
 which I replied:
 {{{
 The attached without the ~ gives:

 $ time ./p 1000000
 Stack space overflow: current size 8388608 bytes.
 Use `+RTS -Ksize' to increase it.
 ./p 1000000  1.96s user 0.05s system 96% cpu 2.095 total

 whereas with the ~ you can pump up the argument as high as you like
 without any runtime or stack use worries:

 $ time ./p 1000000
 'a'
 ./p 1000000  0.00s user 0.00s system 93% cpu 0.004 total

 $ time ./p 1000000000
 'a'
 ./p 1000000000  0.00s user 0.00s system 101% cpu 0.004 total


 For a non-contrived example see the compression package in hackage.
 }}}
 with this program attached:
 {{{
 import Control.Monad.Identity
 import Control.Monad.State
 import System.Environment

 type M = StateT Char Identity

 main = do [x] <- getArgs
           print $ head $ runIdentity $ evalStateT (f $ read x) 'a'

 f :: Int -> M [Char]
 f 0 = return []
 f (n+1) = do st <- get
              rest <- f n
              return (st:rest)
 }}}

 Should you wish to see the whole thread, it begins with
 http://www.haskell.org/pipermail/libraries/2007-January/006805.html

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1127>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to