#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):

 Replying to [comment:11 nsch]:
 > Replying to [comment:10 ehird]:
 > > As far as desugaring goes, I would suggest that it reorder the
 expressions (including flattening nested `mdo`s) to be right-associative,
 and to avoid `mappend`ing things with `mempty`, e.g.
 >
 > Actually, this extension would never ever (!) use `mempty`, which is why
 some have argued that `Monoid` may not exactly be the correct type class
 for this. A `Semigroup` typeclass might be more appropriate:
 >
 > {{{
 > class Semigroup a where
 >   gappend :: a -> a -> a
 > }}}
 >
 > Which should satisfy associativity:
 >
 > {{{
 > (a `gappend` b) `gappend` c = a `gappend` (b `gappend` c)
 > }}}
 >
 > The `Semigroup` instance for monoids is trivial.

 Fair enough; I'd stick with `Monoid` because it's already in base; ideally
 [http://hackage.haskell.org/package/semigroups semigroups] would move in.

 > This would translate to:
 >
 > {{{
 > =>  mdo { as ... } `mappend` bs `mappend` ...
 > =>  (as `mappend` ..) `mappend` bs `mappend` ...
 > }}}
 >
 > Because of associativity this is equivalent to what you suggested.

 My special case was intentional; while the two expressions must have
 equivalent *results*, right-associative use of `mappend` is more efficient
 for basically all `Monoid`s. This is why, e.g. RWH suggests using a
 difference-list rather than `[]` as the monoid of a `Writer`.

 > And by the way, `mdo` is already a reserved key word.

 As I said:

 > 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.

 The new notation for recursive do-notation is `do rec`.

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