Usually in monad tutorials, the = operator for the list monad is
defined as:
m = k = concat (map k m) -- or concatMap k m
but in the GHC sources it's defined as:
m = k = foldr ((++) . k) [] m
As far as I can tell, this definition is equivalent to the previous one
(correct me if
On 16 May 2011 19:07, Michael Vanier mvanie...@gmail.com wrote:
Usually in monad tutorials, the = operator for the list monad is defined
as:
m = k = concat (map k m) -- or concatMap k m
but in the GHC sources it's defined as:
m = k = foldr ((++) . k) [] m
As far as I can tell,
On Monday 16 May 2011 11:07:15, Michael Vanier wrote:
Usually in monad tutorials, the = operator for the list monad is
defined as:
m = k = concat (map k m) -- or concatMap k m
but in the GHC sources it's defined as:
m = k = foldr ((++) . k) [] m
As far as I can tell, this
On 16/05/2011 10:07 AM, Michael Vanier wrote:
Usually in monad tutorials, the = operator for the list monad is
defined as:
m = k = concat (map k m) -- or concatMap k m
but in the GHC sources it's defined as:
m = k = foldr ((++) . k) [] m
As far as I can tell, this definition is equivalent to
Looking at the Core for an utterly trivial example (test x = concatMap
k x where k i = [i..i*2]), the foldr definition seems to cause a
little extra optimization rules to fire, but the result seems pretty
big. The definition using concatMap results in core like this:
main_go2 =
\ (ds_aqV ::
On Mon, May 16, 2011 at 3:49 PM, austin seipp a...@hacks.yi.org wrote:
I don't know why GHC doesn't have this rule by default, though. We can
at least rig it with a RULES pragma, however:
$ cat concatmap.hs
module Main where
{-# RULES
concatMap/foldr forall x k. concatMap k x = foldr ((++)
On Monday 16 May 2011 20:49:35, austin seipp wrote:
Looking at the Core for an utterly trivial example (test x = concatMap
k x where k i = [i..i*2]), the foldr definition seems to cause a
little extra optimization rules to fire, but the result seems pretty
big. The definition using concatMap
You're both right indeed - I didn't look for the definition of
concatMap in GHC.List.
I thought it could be some behavior with the new inliner, so I defined
concatMap in terms of foldr, put it in a seperate module, and then
included it and used it in my test:
Concatmap2.hs:
module Concatmap2
On Monday 16 May 2011 20:49:35, austin seipp wrote:
As you can see, with the foldr definition, GHC is able to fuse the
iteration of the input list with the generation of the result - note
the 'GHC.Base.++' call with the first argument being a list from
[x..x*2], and the second list to append
On Monday 16 May 2011 22:26:18, I wrote:
On Monday 16 May 2011 20:49:35, austin seipp wrote:
As you can see, with the foldr definition, GHC is able to fuse the
iteration of the input list with the generation of the result - note
the 'GHC.Base.++' call with the first argument being a list
10 matches
Mail list logo