#5744: List layouts
---------------------------------+------------------------------------------
    Reporter:  nsch              |       Owner:  nsch            
        Type:  feature request   |      Status:  new             
    Priority:  normal            |   Milestone:                  
   Component:  Compiler          |     Version:  7.2.1           
    Keywords:                    |          Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown    
  Difficulty:  Unknown           |    Testcase:                  
   Blockedby:                    |    Blocking:                  
     Related:                    |  
---------------------------------+------------------------------------------

Comment(by ehird):

 Here's some justifications of this feature from my point of view (talking
 about the version generalised to monoids, as I think it's the best
 option):

 There are quite a few widely-used libraries that use a monad for what is
 essentially an optimised `Writer w ()` over a specific ''w''. Examples:

 * [http://jaspervdj.be/blaze/ blaze-html] uses a
 [http://hackage.haskell.org/packages/archive/blaze-
 html/0.4.3.1/doc/html/src/Text-Blaze-Internal.html#HtmlM laws-breaking
 Monad instance] so it can [http://jaspervdj.be/blaze/tutorial.html use
 layout]

 * [http://hackage.haskell.org/package/cereal cereal] has an
 [http://hackage.haskell.org/packages/archive/cereal/0.3.5.0/doc/html/Data-
 Serialize-Put.html optimised Writer monad] for serialisation; the user
 doesn't care about the PutM monad itself, just the `type Put = PutM ()`
 alias

 So, one thing this is useful for is ''output'' and specification of
 complex nested structures. These monads are exclusively used in a monoidal
 style (indeed, if they're only used with the `()` result type (as e.g.
 blaze-html must be) they're equivalent to monoids), have no use for do-
 notation binds, and would be far more comfortable with a notation
 specifically designed for monoids.

 You could just use `mconcat [...]` everywhere, but writing long lists over
 multiple lines is ugly. A nice thing about a monoid notation is that a lot
 of the libraries can be seen (and can be implemented as) imperatively
 streaming their output to a handle, so an imperative sequencing notation
 and operations like `put :: Word8 -> M` are reasonable. In light of this,
 and because the other proposed names seem too likely to clash to me, my
 favourite name so far is `mdo`, for "monoidal do". The only worry there is
 that it would clash with the obsolete recursive do notation, but it *is*
 deprecated, and its history of being a reserved keyword will mean that
 clashes are unlikely.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5744#comment:9>
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