[Haskell-cafe] HXT: Replace an element with its text

2012-06-25 Thread Michael Orlitzky
I would like to replace,

  foo

with,

  foo

using HXT. So far, the closest I've come is to parse the HTML and apply
the following stuff:

  is_link :: (ArrowXml a) => a XmlTree XmlTree
  is_link =
hasName "a"

  replace_links_with_their_text :: (ArrowXml a) => a XmlTree XmlTree
  replace_links_with_their_text =
processTopDown $ (getText >>> mkText) `when` is_link

Unfortunately, this just removes the "a" element and its text entirely.
The other-closest solution is,

  replace_links_with_their_text :: (ArrowXml a) => a XmlTree XmlTree
  replace_links_with_their_text =
processTopDown $ (txt "foo") `when` is_link

Of course, I don't want to hard-code the value "foo", and I can't figure
out a way to feed the element's text back into 'txt'.

Anyone tried this before?

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage 2 maintainership

2012-06-25 Thread Jeremy Shaw
On Wed, Jun 20, 2012 at 11:06 AM, Ben Gamari  wrote:

> This list is definitely a start. One of the issues that was also
> realized is the size of the server's memory footprint. Unfortunately
> acid-state's requirement that all data either be in memory or have no
> ACID guarantees was found to be a bit of a limitation. If I recall
> correctly some folks were playing around with restructuring the data
> structures a bit to reduce memory usage. I really don't know what
> happened to these efforts.

I am one of those people, but as I (hopefully) mentioned at the time,
I had some other tasks I had to address first (namely, the release of
Happstack 7 and clckwrks). However,  starting this week I am finally
looking at some acid-state related issues. Part of this will be
building some tools to help analyze where all your RAM is going.

My current hypothesis is that for hackage 2, we should be able to
reduce RAM usage by 10 to 100 fold. The size of the data on disk is
only a few MB.. I currently can not think of any good reason why it
should take anywhere as much RAM as it currently does. So, it must be
doing it for some bad reason :) Though, I won't know until I do the
analysis. You'll probably see some blog articles as I work out the
process.

- jeremy

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Martin Odersky on "What's wrong with Monads"

2012-06-25 Thread MightyByte
Jonathan Geddes  gmail.com> writes:
> Cafe,
> 
> I was watching a panel on languages[0] recently and Martin Odersky (the 
creator of Scala) said something about Monads:
> 
> 
> "What's wrong with Monads is that if you go into a Monad you have to change 
your whole syntax from scratch. Every single line of your program changes if 
you 
get it in or out of a Monad. They're not polymorphic so it's really the old 
days 
of Pascal. A monomorphic type system that says 'well that's all I do' ... 
there's no way to abstract over things. " [0, 53:45]
> 
> 
> Thoughts?

In my mind, his first sentence could be paraphrased as follows:

"What's wrong with having a strongly typed mechanism for separating pure and 
effectful code is that pure code and effectful code are actually separate."

Of course every line of your program that uses a Foo will change if you switch 
to IO Foo instead.  If the two were indistinguishable, then you'd have an 
impure 
language instead of a pure one.  Furthermore, this isn't a characteristic 
specific to monads, it's the same for any type constructor whether it's a monad 
or not.

To Martin's credit, earlier in the talk (around 45:15) he makes the following 
statement:

"What you need in the language is the ability to essentially reduce state.  And 
potentially what Scala doesn't do, but for instance Haskell does is to control 
state and purity, and I think that might be the next frontier."

Then at 50:15 he says, "So right now, I think...in the world of effect checking 
we're about where we were with Pascal in terms of static typing."

It seems that his heart is in the right place, but he isn't aware of where we 
actually are right now, and probably doesn't fully appreciate the consequences 
of strongly typed purity.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Unambiguous choice implementation

2012-06-25 Thread Bartosz Milewski
Thanks, Heinrich. I looked at the examples and at the references you
provided. I understand the semantic model, so I guess I'm mostly trying to
understand the implementation. Conal's paper was mostly about refining data
structures in order to provide better implementation. It's all beautiful up
to the point where he introduces the unamb hack. How did you manage to work
around this problem and implement event merging efficiently?
--Bartosz

On Mon, Jun 25, 2012 at 1:30 AM, Heinrich Apfelmus <
apfel...@quantentunnel.de> wrote:

> Bartosz Milewski wrote:
>
>> I'm trying to understand Reactive Banana, but there isn't much
>> documentation to go about.
>>
>
> I haven't written any beginner documentation yet because the API is still
> in flux. The homepage
>
>  
> http://www.haskell.org/**haskellwiki/Reactive-banana
>
> and Stackoverflow
>
>  
> http://stackoverflow.com/**questions/tagged/frp
>
> are great resources, though. Feel free to drop me a line if you have
> questions as well.
>
>
>  How is RB positioned vis a vis Elliott (and then there is the earlier
>> Elliot and Hudak, and the later Elliot with the push implementation and
>> type classes).
>>
>
> The semantics from Elliott (double 't', by the way) and reactive-banana
> are essentially the same, but I have taken the liberty to modernize many
> function names. You can pretty much directly translate Conal's examples to
> reactive-banana, except for those involving the  switcher  combinator.
>
> The approaches to implementation are very different, though. Functional
> reactive programming is one of the cases where you have to learn the API
> without understanding its implementation. (But have a look at the
> Reactive.Banana.Model module, which provides a simplified model
> implementation.)
>
>
>  Do you have a toy applet that demonstrates the use of Reactive Banana,
>> something like Elliotts Bezier editor,  http://research.microsoft.com/**
>> pubs/69665/deop-tr.pdf 
>> ?
>>
>
> Reactive-banana comes with a lot of examples, mentioned here:
>
>  
> http://www.haskell.org/**haskellwiki/Reactive-banana#**documentation
>
>
> By the way, Conal's Bezier editor doesn't make much use of the  switcher
>  combinator, so you can directly translate it into reactive-banana.
>
>
>
> Best regards,
> Heinrich Apfelmus
>
> --
> http://apfelmus.nfshost.com
>
>
> __**_
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/**mailman/listinfo/haskell-cafe
>
> --
> You received this message because you are subscribed to the Google Groups
> "Haskell-cafe" group.
> To post to this group, send email to haskell-c...@googlegroups.com.
> To unsubscribe from this group, send email to haskell-cafe+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/haskell-cafe?hl=en
> .
>
>


-- 
[:Bartosz:]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Munich Haskell Meeting

2012-06-25 Thread Heinrich Hördegen

Dear all,

once again, we want to invite you to our monthly Munich Haskell Meeting 
at Thu, 28th of June, at 19h30.


This time, the venue will be Max Emanuell Brauerei in Munich 
(http://www.max-emanuel-brauerei.de/). Be aware of that change!


Thursday will also be the day of a local football play, at least for 
those living in Europe. Therefore, I want to reserve a table on 
Wednesday in order to get a table at all. If you plan to join, please go 
to:


http://www.haskell-munich.de/dates

and click the button.

Until then, have fun.
Heinrich

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Martin Odersky on "What's wrong with Monads"

2012-06-25 Thread Ernesto Rodriguez
Well,

Monads are something optional at the end. Even the IO Monad is an optional
pattern with unsafePerformIO, but we use it because one of the reasons we
love Haskell is it's ability to differentiate pure and impure functions.
But sadly this is one of the traits we love about Haskell but others
dislike about it.

Cheers,

Ernesto Rodriguez

On Mon, Jun 25, 2012 at 2:23 PM, Alberto G. Corona wrote:

> My pocket explanation:
>
> While e a function gives one only value of the codomain for each element
> of the domain set (and thus it can be evaluated a single time), a category
> is a generalization that accept many graphs that goes from each element of
> the domain to the codomain. For that matter getChar can be understood
> mathematically only using cathegory theory. To discover where the chain of
> graphs goes each time, it is necessary to execute the chain of sentences.
>
> Imperative languages works "categorically" every time, so they don´t need
> an special syntax for doing so. Haskell permits to discriminate functional
> code from "normal" "categorical/imperative" code, so the programmer and the
> compiler can make use of the mathematical properties of functions. For
> example, graph reduction thank to the uniqueness of  the paths.
>
> Besides that, everything, functional or monadic is equally beatiful and
> polimorphic. i don´t think that monadic code is less fine. It is
> unavoidable and no less mathematical.
>
> 2012/6/25 Anton Kholomiov 
>
>> The class you're looking for is Applicative. The (<*>) operator handles
>> application of "effectful" things to "effectful" things, whereas (<$>)
>> handles the application of non-"effectful" things to "effectful" things.
>> This situation is interesting because it highlights the fact that there is
>> a distinction between the meaning of whitespace between function and
>> argument vs the meaning of whitespace between argument and argument.
>>
>>
>> `Applicative` is not enough for monads.
>> `Applicative` is like functor only for functions
>> with many arguments. It's good for patterns:
>>
>> (a -> b -> c -> d) -> (m a -> m b -> m c -> m d)
>>
>> Monads are good for patterns
>>
>> (a -> b -> c -> m d) -> (m a -> m b -> m c -> m d)
>>
>> So I can not express it with `Applicative`. My
>> analogy really breaks down on functions with
>> several arguments, since as you have pointed out there are
>> two white spaces. But I like the idea of using
>> one sign for normal and monadic  and maybe applicative
>> applications.
>>
>> Anton
>>
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ghci session slows down over time.

2012-06-25 Thread Jonathan Geddes
Thanks for the responses.

I am using GHC 7.4.1 an Ubuntu.

Shutting down and restarting ghci is my current workaround. I was hoping
for something a bit less disruptive. :kickoffGC or something like that.

--J Arthur



On Mon, Jun 25, 2012 at 6:54 AM, Ketil Malde  wrote:

> Jonathan Geddes  writes:
>
> > Is this a known issue? More importantly, is there a known workaround?
>
> My experience is that ghci (typically run as an inferior Emacs process)
> often retains a lot of memory.  Thus, I occasionally kill and
> restart it. (Not sure if that counts as a workaround :-)
>
> -k
> --
> If I haven't seen further, it is by standing in the footprints of giants
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Galois is hiring!

2012-06-25 Thread Jason Dagit
We're looking for functional programmers, formal methods practitioners, 
and project leads, interested in either short term or permanent 
employment.  For more information, see: http://corp.galois.com/careers


Why Galois? At Galois, we believe in seeking out and solving important 
problems to make the world a better place.  This philosophy runs through 
everything we do. From internal interactions on an individual level to 
the interesting technical challenges we take on to the way we orient to 
the external world.


We hire the best people, we help them to better understand their own 
passions, and then together we take on important problems.  It just so 
happens that we have skilled software engineers with a passion for 
functional programming who take on challenges in crypto, critical 
systems, secure networking, and so on.


For me, the very compelling reasons to work at Galois are: a strong 
cultural emphasis on freedom to choose your roles within the 
organization including seeking external funding to work on whatever you 
want; strong commitment to open source, and; a cultural emphasis on 
functional programming and formal methods.


What a organization believes has a deep and profound impact on how you 
spend your time at the organization, who the organization attracts, and 
what impact the organization will have in the world. We have no shortage 
of interesting problems to tackle in our quest to make the world a 
better place.


Thanks,
Jason

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Origin of Delimited Continuation Operators

2012-06-25 Thread Stephen Tetley
On 25 June 2012 18:02, Stephen Tetley  wrote:

> Shift for instance is referenced back to at least Davy and Filinski's
> "Abstracting Control" 1990.

Typo - Olivier _Danvy_ not "Davy"

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Origin of Delimited Continuation Operators

2012-06-25 Thread Stephen Tetley
You could try working back from the references in Dorai Sitaram's
"Handling Control" 1993, which is an important paper in the Scheme
community covering this area.

http://www.cs.rice.edu/CS/PLT/Publications/Scheme/pldi93-s.ps.gz

Shift for instance is referenced back to at least Davy and Filinski's
"Abstracting Control" 1990.

On 25 June 2012 03:13, aditya siram  wrote:
> Hi all,
> I working through a few papers and Oleg's delimited continuation
> implementation and I'm wondering how the operators (shift, shift0P,
> control, reset, etc) got their name.
> -deech
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ghci session slows down over time.

2012-06-25 Thread Ketil Malde
Jonathan Geddes  writes:

> Is this a known issue? More importantly, is there a known workaround?

My experience is that ghci (typically run as an inferior Emacs process)
often retains a lot of memory.  Thus, I occasionally kill and
restart it. (Not sure if that counts as a workaround :-)

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Martin Odersky on "What's wrong with Monads"

2012-06-25 Thread Alberto G. Corona
My pocket explanation:

While e a function gives one only value of the codomain for each element of
the domain set (and thus it can be evaluated a single time), a category is
a generalization that accept many graphs that goes from each element of the
domain to the codomain. For that matter getChar can be understood
mathematically only using cathegory theory. To discover where the chain of
graphs goes each time, it is necessary to execute the chain of sentences.

Imperative languages works "categorically" every time, so they don´t need
an special syntax for doing so. Haskell permits to discriminate functional
code from "normal" "categorical/imperative" code, so the programmer and the
compiler can make use of the mathematical properties of functions. For
example, graph reduction thank to the uniqueness of  the paths.

Besides that, everything, functional or monadic is equally beatiful and
polimorphic. i don´t think that monadic code is less fine. It is
unavoidable and no less mathematical.

2012/6/25 Anton Kholomiov 

> The class you're looking for is Applicative. The (<*>) operator handles
> application of "effectful" things to "effectful" things, whereas (<$>)
> handles the application of non-"effectful" things to "effectful" things.
> This situation is interesting because it highlights the fact that there is
> a distinction between the meaning of whitespace between function and
> argument vs the meaning of whitespace between argument and argument.
>
>
> `Applicative` is not enough for monads.
> `Applicative` is like functor only for functions
> with many arguments. It's good for patterns:
>
> (a -> b -> c -> d) -> (m a -> m b -> m c -> m d)
>
> Monads are good for patterns
>
> (a -> b -> c -> m d) -> (m a -> m b -> m c -> m d)
>
> So I can not express it with `Applicative`. My
> analogy really breaks down on functions with
> several arguments, since as you have pointed out there are
> two white spaces. But I like the idea of using
> one sign for normal and monadic  and maybe applicative
> applications.
>
> Anton
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About using "type" to do type alias.

2012-06-25 Thread Ivan Lazar Miljenovic
On 25 June 2012 20:00, Magicloud Magiclouds
 wrote:
> Even more weird, I installed container-0.5.0.0, and now it just compiled!
> I will dig more of that. Sorry to bother you guys.

Possibly your Magiclouds module was using a different version of
containers or something? *shrug*

>
> On Mon, Jun 25, 2012 at 5:53 PM, Magicloud Magiclouds
>  wrote:
>> Interesting, seems like mapM did not effect the problem
>> Let me try more with the first argument of mapM
>>
>> On Mon, Jun 25, 2012 at 5:04 PM, Arlen Cuss  wrote:
>>> Magicloud,
>>>
>>> Try to reduce the particular problem you're having to the smallest possible 
>>> example that reproduces the issue. None of us can compile your code, 
>>> either, because we're missing many of the dependencies, and unfortunately 
>>> the issue is no easier (for me) to track down with the full source listing 
>>> in this case.
>>>
>>> Cheers,
>>>
>>> Arlen
>>>
>>>
>>> On Monday, 25 June 2012 at 5:46 PM, Magicloud Magiclouds wrote:
>>>
 Here is the code, I joined two modules in one paste. Both of them
 cannot pass compiling.

 http://hpaste.org/70418

 On Mon, Jun 25, 2012 at 2:16 PM, Ivan Lazar Miljenovic
 mailto:ivan.miljeno...@gmail.com)> wrote:
 > On 25 June 2012 12:50, Magicloud Magiclouds
 > mailto:magicloud.magiclo...@gmail.com)> 
 > wrote:
 > > Hi,
 > > There was another mail, but the subject might be confusing. So I
 > > write this one. The code is here: http://hpaste.org/70414
 > > If I understand correct, generally, I could use 'type' to do alias
 > > to save the ugly-long code. Like section 1. This works when I 't [(0,
 > > Just "x")]'.
 > >
 > > But, if I wrote section 2. Then 'start (M.fromList $ zip ord_args)
 > > worker' could not be compiled due to the second argument is type of
 > > 'M.Map Arg Arg', not 'JobArgs Arg Arg'.
 >
 >
 >
 > This shouldn't make a difference. As an example, this works:
 >
 > > import qualified Data.Map as M
 > >
 > > type Foo a b = M.Map a b
 > >
 > > fooInsert :: (Ord a) => a -> b -> Foo a b -> Foo a b
 > > fooInsert = M.insert
 >
 >
 >
 > Aliases are just for documentation; they shouldn't affect code working.
 >
 >
 > >
 > > What did I miss to make this work?
 > > --
 > > 竹密岂妨流水过
 > > 山高哪阻野云飞
 > >
 > > And for G+, please use magiclouds#gmail.com (http://gmail.com).
 > >
 > > ___
 > > Haskell-Cafe mailing list
 > > Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
 > > http://www.haskell.org/mailman/listinfo/haskell-cafe
 >
 >
 >
 >
 >
 > --
 > Ivan Lazar Miljenovic
 > ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com)
 > http://IvanMiljenovic.wordpress.com





 --
 竹密岂妨流水过
 山高哪阻野云飞

 And for G+, please use magiclouds#gmail.com (http://gmail.com).

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
 http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>>
>>>
>>
>>
>>
>> --
>> 竹密岂妨流水过
>> 山高哪阻野云飞
>>
>> And for G+, please use magiclouds#gmail.com.
>
>
>
> --
> 竹密岂妨流水过
> 山高哪阻野云飞
>
> And for G+, please use magiclouds#gmail.com.



-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
http://IvanMiljenovic.wordpress.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] not enough fusion?

2012-06-25 Thread Duncan Coutts
On 25 June 2012 02:04, Johannes Waldmann  wrote:
> Dear all,
>
> while doing some benchmarking (*)
> I noticed that function  s1  is considerably faster than  s2
> (but I wanted  s2  because it looks more natural)
> (for n = 1,  s1 takes 20 s, s2 takes 13 s; compiled by ghc-7.4.2 -O2)
>
> s1 :: Int -> Int
> s1 n = sum $ do
>        x <- [ 0 .. n-1 ]
>        return $ sum $ do
>            y <- [ 0 .. n-1 ]
>            return $ gcd x y
>
> s2 :: Int -> Int
> s2 n = sum $ do
>      x <- [ 0 .. n-1 ]
>      y <- [ 0 .. n-1 ]
>      return $ gcd x y
>
> I was expecting that in both programs,
> all lists will be fused away (are they?)

Almost certainly not.

> so the code generator essentially can produce straightforward
> assembly code (no allocations, no closures, etc.)

Unless it changed recently, sum does not fuse (as it is currently
defined, using the current implementation of foldr/build fusion).
Also, lists built using do notation do not (I think) translate into
instances of foldr and build, only list comprehension syntax.

On the first point: sum is a foldl and the current implementation of
foldr/build fusion does not cope well with foldl. While foldl can be
defined in terms of foldr the result is lots of closure allocations.
This could in principle be fixed with an arity raising transformation,
and GHC now does have a simple implementation of this transformation,
so it may be possible to get sum as a foldl to fuse. I'm not sure that
anyone has yet tried changing the sum implementation to try to get it
to fuse. It would be an interesting experiment.

On the second point: ghc has a special desugaring for list
comprehensions (in -O mode) where it turns them into uses of foldr and
build. On the other hand, do notation desugars into bind and return.
I'm not sure how well the result fuses, it uses: foldr ((++) . k) [].

You can find out, just look at the core. If all goes well then you
should see a single list being built and then consumed by sum.

Duncan

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] not enough fusion?

2012-06-25 Thread Lorenzo Bolla
You are right, probably I didn't because I cannot reproduce it now.
Sorry for the noise.
(Anyway, I am still surprised that list-comprehension gives a different
result from do-notation in the list monad.)

L.



On Mon, Jun 25, 2012 at 11:55 AM, Dmitry Olshansky wrote:

> In my test it works ~20% faster than s2 and ~20% slower than s1.
> Did you use -O2 flag?
>
>
> 2012/6/25 Lorenzo Bolla 
>
>> I wonder why this performs really badly, though (I would expect it to be
>> the same as s2):
>>
>> s3 :: Int -> Int
>> s3 n = sum [gcd x y | x <- [ 0 .. n-1 ], y <- [ 0 .. n-1 ]]
>>
>> From the links posted by Dmitry, it might be that the code generated is
>> made of 2 recursive calls: in fact, what I observe is a "stack space
>> overflow" error on runtime...
>>
>> L.
>>
>>
>>
>>
>> On Mon, Jun 25, 2012 at 10:09 AM, Dmitry Olshansky > > wrote:
>>
>>> s1 ~ sum $ map (sum . flip map [0..n] . gcd) [0..n]
>>> s2 ~ sum $ concatMap (flip map [0..n] . gcd) [0..n]
>>>
>>> There are some posts from Joachim Breitner investigated fusion for
>>> concatMap:
>>>
>>> http://www.haskell.org/pipermail/haskell-cafe/2011-December/thread.html#97227
>>>
>>>
>>>
>>> 2012/6/25 Johannes Waldmann 
>>>
 Dear all,

 while doing some benchmarking (*)
 I noticed that function  s1  is considerably faster than  s2
 (but I wanted  s2  because it looks more natural)
 (for n = 1,  s1 takes 20 s, s2 takes 13 s; compiled by ghc-7.4.2
 -O2)

 s1 :: Int -> Int
 s1 n = sum $ do
x <- [ 0 .. n-1 ]
return $ sum $ do
y <- [ 0 .. n-1 ]
return $ gcd x y

 s2 :: Int -> Int
 s2 n = sum $ do
  x <- [ 0 .. n-1 ]
  y <- [ 0 .. n-1 ]
  return $ gcd x y

 I was expecting that in both programs,
 all lists will be fused away (are they?)
 so the code generator essentially can produce straightforward
 assembly code (no allocations, no closures, etc.)


 For reference, I also wrote the equivalent imperative program
 (two nested loops, one accumulator for the sum)
 (with the straightforward recursive gcd)
 and runtimes are (for same input as above)

 C/gcc: 7.3 s , Java: 7.7 s, C#/Mono: 8.7 s


 So, they sort of agree with each other, but disagree with ghc.
 Where does the factor 2 come from? Lists? Laziness?
 Does  ghc  turn the tail recursion (in gcd) into a loop? (gcc does).
 (I am looking at  -ddump-asm  but can't quite see through it.)


 (*) benchmarking to show that today's compilers are clever enough
 such that the choice of paradigm/language does not really matter
 for this kind of low-level programming.






 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

>>>
>>>
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>>
>>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] not enough fusion?

2012-06-25 Thread Dmitry Olshansky
In my test it works ~20% faster than s2 and ~20% slower than s1.
Did you use -O2 flag?

2012/6/25 Lorenzo Bolla 

> I wonder why this performs really badly, though (I would expect it to be
> the same as s2):
>
> s3 :: Int -> Int
> s3 n = sum [gcd x y | x <- [ 0 .. n-1 ], y <- [ 0 .. n-1 ]]
>
> From the links posted by Dmitry, it might be that the code generated is
> made of 2 recursive calls: in fact, what I observe is a "stack space
> overflow" error on runtime...
>
> L.
>
>
>
>
> On Mon, Jun 25, 2012 at 10:09 AM, Dmitry Olshansky 
> wrote:
>
>> s1 ~ sum $ map (sum . flip map [0..n] . gcd) [0..n]
>> s2 ~ sum $ concatMap (flip map [0..n] . gcd) [0..n]
>>
>> There are some posts from Joachim Breitner investigated fusion for
>> concatMap:
>>
>> http://www.haskell.org/pipermail/haskell-cafe/2011-December/thread.html#97227
>>
>>
>>
>> 2012/6/25 Johannes Waldmann 
>>
>>> Dear all,
>>>
>>> while doing some benchmarking (*)
>>> I noticed that function  s1  is considerably faster than  s2
>>> (but I wanted  s2  because it looks more natural)
>>> (for n = 1,  s1 takes 20 s, s2 takes 13 s; compiled by ghc-7.4.2 -O2)
>>>
>>> s1 :: Int -> Int
>>> s1 n = sum $ do
>>>x <- [ 0 .. n-1 ]
>>>return $ sum $ do
>>>y <- [ 0 .. n-1 ]
>>>return $ gcd x y
>>>
>>> s2 :: Int -> Int
>>> s2 n = sum $ do
>>>  x <- [ 0 .. n-1 ]
>>>  y <- [ 0 .. n-1 ]
>>>  return $ gcd x y
>>>
>>> I was expecting that in both programs,
>>> all lists will be fused away (are they?)
>>> so the code generator essentially can produce straightforward
>>> assembly code (no allocations, no closures, etc.)
>>>
>>>
>>> For reference, I also wrote the equivalent imperative program
>>> (two nested loops, one accumulator for the sum)
>>> (with the straightforward recursive gcd)
>>> and runtimes are (for same input as above)
>>>
>>> C/gcc: 7.3 s , Java: 7.7 s, C#/Mono: 8.7 s
>>>
>>>
>>> So, they sort of agree with each other, but disagree with ghc.
>>> Where does the factor 2 come from? Lists? Laziness?
>>> Does  ghc  turn the tail recursion (in gcd) into a loop? (gcc does).
>>> (I am looking at  -ddump-asm  but can't quite see through it.)
>>>
>>>
>>> (*) benchmarking to show that today's compilers are clever enough
>>> such that the choice of paradigm/language does not really matter
>>> for this kind of low-level programming.
>>>
>>>
>>>
>>>
>>>
>>>
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About using "type" to do type alias.

2012-06-25 Thread Arlen Cuss
Glad you worked it out! :) Usually isolating the part of concern in a 
mysterious error will help shed light on the source!

Cheers,

Arlen  


On Monday, 25 June 2012 at 8:00 PM, Magicloud Magiclouds wrote:

> Even more weird, I installed container-0.5.0.0, and now it just compiled!
> I will dig more of that. Sorry to bother you guys.
>  
> On Mon, Jun 25, 2012 at 5:53 PM, Magicloud Magiclouds
> mailto:magicloud.magiclo...@gmail.com)> 
> wrote:
> > Interesting, seems like mapM did not effect the problem
> > Let me try more with the first argument of mapM
> >  
> > On Mon, Jun 25, 2012 at 5:04 PM, Arlen Cuss  > (mailto:a...@len.me)> wrote:
> > > Magicloud,
> > >  
> > > Try to reduce the particular problem you're having to the smallest 
> > > possible example that reproduces the issue. None of us can compile your 
> > > code, either, because we're missing many of the dependencies, and 
> > > unfortunately the issue is no easier (for me) to track down with the full 
> > > source listing in this case.
> > >  
> > > Cheers,
> > >  
> > > Arlen
> > >  
> > >  
> > > On Monday, 25 June 2012 at 5:46 PM, Magicloud Magiclouds wrote:
> > >  
> > > > Here is the code, I joined two modules in one paste. Both of them
> > > > cannot pass compiling.
> > > >  
> > > > http://hpaste.org/70418
> > > >  
> > > > On Mon, Jun 25, 2012 at 2:16 PM, Ivan Lazar Miljenovic
> > > > mailto:ivan.miljeno...@gmail.com)> wrote:
> > > > > On 25 June 2012 12:50, Magicloud Magiclouds
> > > > >  > > > > (mailto:magicloud.magiclo...@gmail.com)> wrote:
> > > > > > Hi,
> > > > > > There was another mail, but the subject might be confusing. So I
> > > > > > write this one. The code is here: http://hpaste.org/70414
> > > > > > If I understand correct, generally, I could use 'type' to do alias
> > > > > > to save the ugly-long code. Like section 1. This works when I 't 
> > > > > > [(0,
> > > > > > Just "x")]'.
> > > > > >  
> > > > > > But, if I wrote section 2. Then 'start (M.fromList $ zip ord_args)
> > > > > > worker' could not be compiled due to the second argument is type of
> > > > > > 'M.Map Arg Arg', not 'JobArgs Arg Arg'.
> > > > >  
> > > > >  
> > > > >  
> > > > >  
> > > > >  
> > > > > This shouldn't make a difference. As an example, this works:
> > > > >  
> > > > > > import qualified Data.Map as M
> > > > > >  
> > > > > > type Foo a b = M.Map a b
> > > > > >  
> > > > > > fooInsert :: (Ord a) => a -> b -> Foo a b -> Foo a b
> > > > > > fooInsert = M.insert
> > > > >  
> > > > >  
> > > > >  
> > > > >  
> > > > >  
> > > > > Aliases are just for documentation; they shouldn't affect code 
> > > > > working.
> > > > >  
> > > > >  
> > > > > >  
> > > > > > What did I miss to make this work?
> > > > > > --
> > > > > > 竹密岂妨流水过
> > > > > > 山高哪阻野云飞
> > > > > >  
> > > > > > And for G+, please use magiclouds#gmail.com (http://gmail.com).
> > > > > >  
> > > > > > ___
> > > > > > Haskell-Cafe mailing list
> > > > > > Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
> > > > > > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > > > >  
> > > > >  
> > > > >  
> > > > >  
> > > > >  
> > > > >  
> > > > >  
> > > > > --
> > > > > Ivan Lazar Miljenovic
> > > > > ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com)
> > > > > http://IvanMiljenovic.wordpress.com
> > > >  
> > > >  
> > > >  
> > > >  
> > > >  
> > > >  
> > > >  
> > > > --
> > > > 竹密岂妨流水过
> > > > 山高哪阻野云飞
> > > >  
> > > > And for G+, please use magiclouds#gmail.com (http://gmail.com).
> > > >  
> > > > ___
> > > > Haskell-Cafe mailing list
> > > > Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
> > > > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > >  
> >  
> >  
> >  
> >  
> >  
> > --
> > 竹密岂妨流水过
> > 山高哪阻野云飞
> >  
> > And for G+, please use magiclouds#gmail.com (http://gmail.com).
>  
>  
>  
> --  
> 竹密岂妨流水过
> 山高哪阻野云飞
>  
> And for G+, please use magiclouds#gmail.com (http://gmail.com).  



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About using "type" to do type alias.

2012-06-25 Thread Magicloud Magiclouds
Even more weird, I installed container-0.5.0.0, and now it just compiled!
I will dig more of that. Sorry to bother you guys.

On Mon, Jun 25, 2012 at 5:53 PM, Magicloud Magiclouds
 wrote:
> Interesting, seems like mapM did not effect the problem
> Let me try more with the first argument of mapM
>
> On Mon, Jun 25, 2012 at 5:04 PM, Arlen Cuss  wrote:
>> Magicloud,
>>
>> Try to reduce the particular problem you're having to the smallest possible 
>> example that reproduces the issue. None of us can compile your code, either, 
>> because we're missing many of the dependencies, and unfortunately the issue 
>> is no easier (for me) to track down with the full source listing in this 
>> case.
>>
>> Cheers,
>>
>> Arlen
>>
>>
>> On Monday, 25 June 2012 at 5:46 PM, Magicloud Magiclouds wrote:
>>
>>> Here is the code, I joined two modules in one paste. Both of them
>>> cannot pass compiling.
>>>
>>> http://hpaste.org/70418
>>>
>>> On Mon, Jun 25, 2012 at 2:16 PM, Ivan Lazar Miljenovic
>>> mailto:ivan.miljeno...@gmail.com)> wrote:
>>> > On 25 June 2012 12:50, Magicloud Magiclouds
>>> > mailto:magicloud.magiclo...@gmail.com)> 
>>> > wrote:
>>> > > Hi,
>>> > > There was another mail, but the subject might be confusing. So I
>>> > > write this one. The code is here: http://hpaste.org/70414
>>> > > If I understand correct, generally, I could use 'type' to do alias
>>> > > to save the ugly-long code. Like section 1. This works when I 't [(0,
>>> > > Just "x")]'.
>>> > >
>>> > > But, if I wrote section 2. Then 'start (M.fromList $ zip ord_args)
>>> > > worker' could not be compiled due to the second argument is type of
>>> > > 'M.Map Arg Arg', not 'JobArgs Arg Arg'.
>>> >
>>> >
>>> >
>>> > This shouldn't make a difference. As an example, this works:
>>> >
>>> > > import qualified Data.Map as M
>>> > >
>>> > > type Foo a b = M.Map a b
>>> > >
>>> > > fooInsert :: (Ord a) => a -> b -> Foo a b -> Foo a b
>>> > > fooInsert = M.insert
>>> >
>>> >
>>> >
>>> > Aliases are just for documentation; they shouldn't affect code working.
>>> >
>>> >
>>> > >
>>> > > What did I miss to make this work?
>>> > > --
>>> > > 竹密岂妨流水过
>>> > > 山高哪阻野云飞
>>> > >
>>> > > And for G+, please use magiclouds#gmail.com (http://gmail.com).
>>> > >
>>> > > ___
>>> > > Haskell-Cafe mailing list
>>> > > Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
>>> > > http://www.haskell.org/mailman/listinfo/haskell-cafe
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > Ivan Lazar Miljenovic
>>> > ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com)
>>> > http://IvanMiljenovic.wordpress.com
>>>
>>>
>>>
>>>
>>>
>>> --
>>> 竹密岂妨流水过
>>> 山高哪阻野云飞
>>>
>>> And for G+, please use magiclouds#gmail.com (http://gmail.com).
>>>
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>>
>
>
>
> --
> 竹密岂妨流水过
> 山高哪阻野云飞
>
> And for G+, please use magiclouds#gmail.com.



-- 
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About using "type" to do type alias.

2012-06-25 Thread Magicloud Magiclouds
Interesting, seems like mapM did not effect the problem
Let me try more with the first argument of mapM

On Mon, Jun 25, 2012 at 5:04 PM, Arlen Cuss  wrote:
> Magicloud,
>
> Try to reduce the particular problem you're having to the smallest possible 
> example that reproduces the issue. None of us can compile your code, either, 
> because we're missing many of the dependencies, and unfortunately the issue 
> is no easier (for me) to track down with the full source listing in this case.
>
> Cheers,
>
> Arlen
>
>
> On Monday, 25 June 2012 at 5:46 PM, Magicloud Magiclouds wrote:
>
>> Here is the code, I joined two modules in one paste. Both of them
>> cannot pass compiling.
>>
>> http://hpaste.org/70418
>>
>> On Mon, Jun 25, 2012 at 2:16 PM, Ivan Lazar Miljenovic
>> mailto:ivan.miljeno...@gmail.com)> wrote:
>> > On 25 June 2012 12:50, Magicloud Magiclouds
>> > mailto:magicloud.magiclo...@gmail.com)> 
>> > wrote:
>> > > Hi,
>> > > There was another mail, but the subject might be confusing. So I
>> > > write this one. The code is here: http://hpaste.org/70414
>> > > If I understand correct, generally, I could use 'type' to do alias
>> > > to save the ugly-long code. Like section 1. This works when I 't [(0,
>> > > Just "x")]'.
>> > >
>> > > But, if I wrote section 2. Then 'start (M.fromList $ zip ord_args)
>> > > worker' could not be compiled due to the second argument is type of
>> > > 'M.Map Arg Arg', not 'JobArgs Arg Arg'.
>> >
>> >
>> >
>> > This shouldn't make a difference. As an example, this works:
>> >
>> > > import qualified Data.Map as M
>> > >
>> > > type Foo a b = M.Map a b
>> > >
>> > > fooInsert :: (Ord a) => a -> b -> Foo a b -> Foo a b
>> > > fooInsert = M.insert
>> >
>> >
>> >
>> > Aliases are just for documentation; they shouldn't affect code working.
>> >
>> >
>> > >
>> > > What did I miss to make this work?
>> > > --
>> > > 竹密岂妨流水过
>> > > 山高哪阻野云飞
>> > >
>> > > And for G+, please use magiclouds#gmail.com (http://gmail.com).
>> > >
>> > > ___
>> > > Haskell-Cafe mailing list
>> > > Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
>> > > http://www.haskell.org/mailman/listinfo/haskell-cafe
>> >
>> >
>> >
>> >
>> >
>> > --
>> > Ivan Lazar Miljenovic
>> > ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com)
>> > http://IvanMiljenovic.wordpress.com
>>
>>
>>
>>
>>
>> --
>> 竹密岂妨流水过
>> 山高哪阻野云飞
>>
>> And for G+, please use magiclouds#gmail.com (http://gmail.com).
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>



-- 
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] not enough fusion?

2012-06-25 Thread Lorenzo Bolla
I wonder why this performs really badly, though (I would expect it to be
the same as s2):

s3 :: Int -> Int
s3 n = sum [gcd x y | x <- [ 0 .. n-1 ], y <- [ 0 .. n-1 ]]

>From the links posted by Dmitry, it might be that the code generated is
made of 2 recursive calls: in fact, what I observe is a "stack space
overflow" error on runtime...

L.




On Mon, Jun 25, 2012 at 10:09 AM, Dmitry Olshansky wrote:

> s1 ~ sum $ map (sum . flip map [0..n] . gcd) [0..n]
> s2 ~ sum $ concatMap (flip map [0..n] . gcd) [0..n]
>
> There are some posts from Joachim Breitner investigated fusion for
> concatMap:
>
> http://www.haskell.org/pipermail/haskell-cafe/2011-December/thread.html#97227
>
>
>
> 2012/6/25 Johannes Waldmann 
>
>> Dear all,
>>
>> while doing some benchmarking (*)
>> I noticed that function  s1  is considerably faster than  s2
>> (but I wanted  s2  because it looks more natural)
>> (for n = 1,  s1 takes 20 s, s2 takes 13 s; compiled by ghc-7.4.2 -O2)
>>
>> s1 :: Int -> Int
>> s1 n = sum $ do
>>x <- [ 0 .. n-1 ]
>>return $ sum $ do
>>y <- [ 0 .. n-1 ]
>>return $ gcd x y
>>
>> s2 :: Int -> Int
>> s2 n = sum $ do
>>  x <- [ 0 .. n-1 ]
>>  y <- [ 0 .. n-1 ]
>>  return $ gcd x y
>>
>> I was expecting that in both programs,
>> all lists will be fused away (are they?)
>> so the code generator essentially can produce straightforward
>> assembly code (no allocations, no closures, etc.)
>>
>>
>> For reference, I also wrote the equivalent imperative program
>> (two nested loops, one accumulator for the sum)
>> (with the straightforward recursive gcd)
>> and runtimes are (for same input as above)
>>
>> C/gcc: 7.3 s , Java: 7.7 s, C#/Mono: 8.7 s
>>
>>
>> So, they sort of agree with each other, but disagree with ghc.
>> Where does the factor 2 come from? Lists? Laziness?
>> Does  ghc  turn the tail recursion (in gcd) into a loop? (gcc does).
>> (I am looking at  -ddump-asm  but can't quite see through it.)
>>
>>
>> (*) benchmarking to show that today's compilers are clever enough
>> such that the choice of paradigm/language does not really matter
>> for this kind of low-level programming.
>>
>>
>>
>>
>>
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About using "type" to do type alias.

2012-06-25 Thread Magicloud Magiclouds
Sorry, I forgot that. Magicloud.Map.mapM sure is a helper I use as
lifted Data.Map.map.
If I changed the type of the result of start, the Jobs module
compiled. But still cannot compile with the other module (which uses
start). And the error is on JobArgs.
I post the function here, I am not sure how could I fix it.

mapM :: (Monad m, Ord k) => (a -> m b) -> M.Map k a -> m (M.Map k b)
mapM f m =
  let (ks, as) = unzip $ M.toList m
  in
Prelude.mapM f as >>=
  return . M.fromList . zip ks

On Mon, Jun 25, 2012 at 5:11 PM, Ivan Lazar Miljenovic
 wrote:
> On 25 June 2012 19:04, Arlen Cuss  wrote:
>> Magicloud,
>>
>> Try to reduce the particular problem you're having to the smallest possible 
>> example that reproduces the issue. None of us can compile your code, either, 
>> because we're missing many of the dependencies, and unfortunately the issue 
>> is no easier (for me) to track down with the full source listing in this 
>> case.
>
> Though line 22 reveals something: I don't know what Magicloud.Map.mapM
> is, though I'm guessing it's a lifted version of Data.Map.map.
> However, I would guess that it's a type problem.
>
> Try changing the type of start to be ` start :: (Ord k, Exception e)
> => JobArgs k a -> (a -> IO b) -> IO (M.Map k (JobInfo a e)) '; I would
> hazard a guess that you would get the same error, and thus the problem
> isn't with `type', it's that your mapping function isn't quite
> correct.
>
>>
>> Cheers,
>>
>> Arlen
>>
>>
>> On Monday, 25 June 2012 at 5:46 PM, Magicloud Magiclouds wrote:
>>
>>> Here is the code, I joined two modules in one paste. Both of them
>>> cannot pass compiling.
>>>
>>> http://hpaste.org/70418
>>>
>>> On Mon, Jun 25, 2012 at 2:16 PM, Ivan Lazar Miljenovic
>>> mailto:ivan.miljeno...@gmail.com)> wrote:
>>> > On 25 June 2012 12:50, Magicloud Magiclouds
>>> > mailto:magicloud.magiclo...@gmail.com)> 
>>> > wrote:
>>> > > Hi,
>>> > > There was another mail, but the subject might be confusing. So I
>>> > > write this one. The code is here: http://hpaste.org/70414
>>> > > If I understand correct, generally, I could use 'type' to do alias
>>> > > to save the ugly-long code. Like section 1. This works when I 't [(0,
>>> > > Just "x")]'.
>>> > >
>>> > > But, if I wrote section 2. Then 'start (M.fromList $ zip ord_args)
>>> > > worker' could not be compiled due to the second argument is type of
>>> > > 'M.Map Arg Arg', not 'JobArgs Arg Arg'.
>>> >
>>> >
>>> >
>>> > This shouldn't make a difference. As an example, this works:
>>> >
>>> > > import qualified Data.Map as M
>>> > >
>>> > > type Foo a b = M.Map a b
>>> > >
>>> > > fooInsert :: (Ord a) => a -> b -> Foo a b -> Foo a b
>>> > > fooInsert = M.insert
>>> >
>>> >
>>> >
>>> > Aliases are just for documentation; they shouldn't affect code working.
>>> >
>>> >
>>> > >
>>> > > What did I miss to make this work?
>>> > > --
>>> > > 竹密岂妨流水过
>>> > > 山高哪阻野云飞
>>> > >
>>> > > And for G+, please use magiclouds#gmail.com (http://gmail.com).
>>> > >
>>> > > ___
>>> > > Haskell-Cafe mailing list
>>> > > Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
>>> > > http://www.haskell.org/mailman/listinfo/haskell-cafe
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > Ivan Lazar Miljenovic
>>> > ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com)
>>> > http://IvanMiljenovic.wordpress.com
>>>
>>>
>>>
>>>
>>>
>>> --
>>> 竹密岂妨流水过
>>> 山高哪阻野云飞
>>>
>>> And for G+, please use magiclouds#gmail.com (http://gmail.com).
>>>
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>>
>
>
>
> --
> Ivan Lazar Miljenovic
> ivan.miljeno...@gmail.com
> http://IvanMiljenovic.wordpress.com



-- 
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About using "type" to do type alias.

2012-06-25 Thread Ivan Lazar Miljenovic
On 25 June 2012 19:04, Arlen Cuss  wrote:
> Magicloud,
>
> Try to reduce the particular problem you're having to the smallest possible 
> example that reproduces the issue. None of us can compile your code, either, 
> because we're missing many of the dependencies, and unfortunately the issue 
> is no easier (for me) to track down with the full source listing in this case.

Though line 22 reveals something: I don't know what Magicloud.Map.mapM
is, though I'm guessing it's a lifted version of Data.Map.map.
However, I would guess that it's a type problem.

Try changing the type of start to be ` start :: (Ord k, Exception e)
=> JobArgs k a -> (a -> IO b) -> IO (M.Map k (JobInfo a e)) '; I would
hazard a guess that you would get the same error, and thus the problem
isn't with `type', it's that your mapping function isn't quite
correct.

>
> Cheers,
>
> Arlen
>
>
> On Monday, 25 June 2012 at 5:46 PM, Magicloud Magiclouds wrote:
>
>> Here is the code, I joined two modules in one paste. Both of them
>> cannot pass compiling.
>>
>> http://hpaste.org/70418
>>
>> On Mon, Jun 25, 2012 at 2:16 PM, Ivan Lazar Miljenovic
>> mailto:ivan.miljeno...@gmail.com)> wrote:
>> > On 25 June 2012 12:50, Magicloud Magiclouds
>> > mailto:magicloud.magiclo...@gmail.com)> 
>> > wrote:
>> > > Hi,
>> > > There was another mail, but the subject might be confusing. So I
>> > > write this one. The code is here: http://hpaste.org/70414
>> > > If I understand correct, generally, I could use 'type' to do alias
>> > > to save the ugly-long code. Like section 1. This works when I 't [(0,
>> > > Just "x")]'.
>> > >
>> > > But, if I wrote section 2. Then 'start (M.fromList $ zip ord_args)
>> > > worker' could not be compiled due to the second argument is type of
>> > > 'M.Map Arg Arg', not 'JobArgs Arg Arg'.
>> >
>> >
>> >
>> > This shouldn't make a difference. As an example, this works:
>> >
>> > > import qualified Data.Map as M
>> > >
>> > > type Foo a b = M.Map a b
>> > >
>> > > fooInsert :: (Ord a) => a -> b -> Foo a b -> Foo a b
>> > > fooInsert = M.insert
>> >
>> >
>> >
>> > Aliases are just for documentation; they shouldn't affect code working.
>> >
>> >
>> > >
>> > > What did I miss to make this work?
>> > > --
>> > > 竹密岂妨流水过
>> > > 山高哪阻野云飞
>> > >
>> > > And for G+, please use magiclouds#gmail.com (http://gmail.com).
>> > >
>> > > ___
>> > > Haskell-Cafe mailing list
>> > > Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
>> > > http://www.haskell.org/mailman/listinfo/haskell-cafe
>> >
>> >
>> >
>> >
>> >
>> > --
>> > Ivan Lazar Miljenovic
>> > ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com)
>> > http://IvanMiljenovic.wordpress.com
>>
>>
>>
>>
>>
>> --
>> 竹密岂妨流水过
>> 山高哪阻野云飞
>>
>> And for G+, please use magiclouds#gmail.com (http://gmail.com).
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>



-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
http://IvanMiljenovic.wordpress.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] not enough fusion?

2012-06-25 Thread Dmitry Olshansky
s1 ~ sum $ map (sum . flip map [0..n] . gcd) [0..n]
s2 ~ sum $ concatMap (flip map [0..n] . gcd) [0..n]

There are some posts from Joachim Breitner investigated fusion for
concatMap:
http://www.haskell.org/pipermail/haskell-cafe/2011-December/thread.html#97227



2012/6/25 Johannes Waldmann 

> Dear all,
>
> while doing some benchmarking (*)
> I noticed that function  s1  is considerably faster than  s2
> (but I wanted  s2  because it looks more natural)
> (for n = 1,  s1 takes 20 s, s2 takes 13 s; compiled by ghc-7.4.2 -O2)
>
> s1 :: Int -> Int
> s1 n = sum $ do
>x <- [ 0 .. n-1 ]
>return $ sum $ do
>y <- [ 0 .. n-1 ]
>return $ gcd x y
>
> s2 :: Int -> Int
> s2 n = sum $ do
>  x <- [ 0 .. n-1 ]
>  y <- [ 0 .. n-1 ]
>  return $ gcd x y
>
> I was expecting that in both programs,
> all lists will be fused away (are they?)
> so the code generator essentially can produce straightforward
> assembly code (no allocations, no closures, etc.)
>
>
> For reference, I also wrote the equivalent imperative program
> (two nested loops, one accumulator for the sum)
> (with the straightforward recursive gcd)
> and runtimes are (for same input as above)
>
> C/gcc: 7.3 s , Java: 7.7 s, C#/Mono: 8.7 s
>
>
> So, they sort of agree with each other, but disagree with ghc.
> Where does the factor 2 come from? Lists? Laziness?
> Does  ghc  turn the tail recursion (in gcd) into a loop? (gcc does).
> (I am looking at  -ddump-asm  but can't quite see through it.)
>
>
> (*) benchmarking to show that today's compilers are clever enough
> such that the choice of paradigm/language does not really matter
> for this kind of low-level programming.
>
>
>
>
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About using "type" to do type alias.

2012-06-25 Thread Arlen Cuss
Magicloud,

Try to reduce the particular problem you're having to the smallest possible 
example that reproduces the issue. None of us can compile your code, either, 
because we're missing many of the dependencies, and unfortunately the issue is 
no easier (for me) to track down with the full source listing in this case.

Cheers,

Arlen  


On Monday, 25 June 2012 at 5:46 PM, Magicloud Magiclouds wrote:

> Here is the code, I joined two modules in one paste. Both of them
> cannot pass compiling.
>  
> http://hpaste.org/70418
>  
> On Mon, Jun 25, 2012 at 2:16 PM, Ivan Lazar Miljenovic
> mailto:ivan.miljeno...@gmail.com)> wrote:
> > On 25 June 2012 12:50, Magicloud Magiclouds
> > mailto:magicloud.magiclo...@gmail.com)> 
> > wrote:
> > > Hi,
> > > There was another mail, but the subject might be confusing. So I
> > > write this one. The code is here: http://hpaste.org/70414
> > > If I understand correct, generally, I could use 'type' to do alias
> > > to save the ugly-long code. Like section 1. This works when I 't [(0,
> > > Just "x")]'.
> > >  
> > > But, if I wrote section 2. Then 'start (M.fromList $ zip ord_args)
> > > worker' could not be compiled due to the second argument is type of
> > > 'M.Map Arg Arg', not 'JobArgs Arg Arg'.
> >  
> >  
> >  
> > This shouldn't make a difference. As an example, this works:
> >  
> > > import qualified Data.Map as M
> > >  
> > > type Foo a b = M.Map a b
> > >  
> > > fooInsert :: (Ord a) => a -> b -> Foo a b -> Foo a b
> > > fooInsert = M.insert
> >  
> >  
> >  
> > Aliases are just for documentation; they shouldn't affect code working.
> >  
> >  
> > >  
> > > What did I miss to make this work?
> > > --
> > > 竹密岂妨流水过
> > > 山高哪阻野云飞
> > >  
> > > And for G+, please use magiclouds#gmail.com (http://gmail.com).
> > >  
> > > ___
> > > Haskell-Cafe mailing list
> > > Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
> > > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >  
> >  
> >  
> >  
> >  
> > --
> > Ivan Lazar Miljenovic
> > ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com)
> > http://IvanMiljenovic.wordpress.com
>  
>  
>  
>  
>  
> --  
> 竹密岂妨流水过
> 山高哪阻野云飞
>  
> And for G+, please use magiclouds#gmail.com (http://gmail.com).
>  
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org)
> http://www.haskell.org/mailman/listinfo/haskell-cafe




___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Unambiguous choice implementation

2012-06-25 Thread Heinrich Apfelmus

Bartosz Milewski wrote:
I'm trying to understand Reactive Banana, but there isn't much 
documentation to go about.


I haven't written any beginner documentation yet because the API is 
still in flux. The homepage


  http://www.haskell.org/haskellwiki/Reactive-banana

and Stackoverflow

  http://stackoverflow.com/questions/tagged/frp

are great resources, though. Feel free to drop me a line if you have 
questions as well.


How is RB positioned vis a vis Elliott (and then 
there is the earlier Elliot and Hudak, and the later Elliot with the push 
implementation and type classes).


The semantics from Elliott (double 't', by the way) and reactive-banana 
are essentially the same, but I have taken the liberty to modernize many 
function names. You can pretty much directly translate Conal's examples 
to reactive-banana, except for those involving the  switcher  combinator.


The approaches to implementation are very different, though. Functional 
reactive programming is one of the cases where you have to learn the API 
without understanding its implementation. (But have a look at the 
Reactive.Banana.Model module, which provides a simplified model 
implementation.)


Do you have a toy applet that 
demonstrates the use of Reactive Banana, something like Elliotts Bezier 
editor,  http://research.microsoft.com/pubs/69665/deop-tr.pdf  ? 


Reactive-banana comes with a lot of examples, mentioned here:

  http://www.haskell.org/haskellwiki/Reactive-banana#documentation


By the way, Conal's Bezier editor doesn't make much use of the  switcher 
 combinator, so you can directly translate it into reactive-banana.



Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About using "type" to do type alias.

2012-06-25 Thread Magicloud Magiclouds
Here is the code, I joined two modules in one paste. Both of them
cannot pass compiling.

http://hpaste.org/70418

On Mon, Jun 25, 2012 at 2:16 PM, Ivan Lazar Miljenovic
 wrote:
> On 25 June 2012 12:50, Magicloud Magiclouds
>  wrote:
>> Hi,
>>  There was another mail, but the subject might be confusing. So I
>> write this one. The code is here: http://hpaste.org/70414
>>  If I understand correct, generally, I could use 'type' to do alias
>> to save the ugly-long code. Like section 1. This works when I 't [(0,
>> Just "x")]'.
>>
>>  But, if I wrote section 2. Then 'start (M.fromList $ zip ord_args)
>> worker' could not be compiled due to the second argument is type of
>> 'M.Map Arg Arg', not 'JobArgs Arg Arg'.
>
> This shouldn't make a difference.  As an example, this works:
>
>> import qualified Data.Map as M
>>
>> type Foo a b = M.Map a b
>>
>> fooInsert :: (Ord a) => a -> b -> Foo a b -> Foo a b
>> fooInsert = M.insert
>
> Aliases are just for documentation; they shouldn't affect code working.
>
>
>>
>>  What did I miss to make this work?
>> --
>> 竹密岂妨流水过
>> 山高哪阻野云飞
>>
>> And for G+, please use magiclouds#gmail.com.
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
> --
> Ivan Lazar Miljenovic
> ivan.miljeno...@gmail.com
> http://IvanMiljenovic.wordpress.com



-- 
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ICFP Student Research Competition

2012-06-25 Thread Wouter Swierstra
=
Student Research Competition

  Associated with the
   The 17th ACM SIGPLAN International Conference
 on Functional Programming (ICFP 2012) and
 affiliated events

   http://www.icfpconference.org/icfp2012/src.html
Copenhagen, Denmark, Sep 9-15, 2012
=


This year ICFP will host a Student Research Competition where
undergraduate and postgraduate students can present posters. The
SRC at the ICFP 2012 consists of three rounds:

 - Extended abstract round: All students are encouraged to submit an
extended abstract outlining their research (800 words).

 - Poster session at ICFP 2012: Based on the abstracts, a panel
of judges will select the most promising entrants to participate
in the poster session which will take place at ICFP. Students who
make it to this round will be supported to attend the conference,
to a maximum of $500 for travel and housing.  If your total costs
are higher than these $500 your conference fee may be waived too.
In the poster session, students will have the opportunity to
present their work to the judges, who will select three finalists
in each category* (graduate/undergraduate) to advance to the next
round.

 - ICFP presentation: The next round consists of an oral
presentation at the ICFP to compete for the final awards in each
category.

** Prizes **

Both the top three graduate and the top three undergraduate contestants
will receive prizes of $500, $300, and $200, respectively.  All six
winners will receive award medals and a two-year complimentary ACM
student membership, including a subscription to ACM’s Digital
Library. The names of the winners will be posted on the SRC web
site.

The winners in each category will be invited to participate in
the ACM SRC Grand Finals, an on-line round of competitions among the
winners of other conference-hosted SRCs. Grand Finalists and their
advisors will be invited to the Annual ACM Awards Banquet for an
all-expenses-paid trip, where they will be recognized for their
accomplishments along with other prestigious ACM award winners,
including the winner of the Turing Award (also known as the Nobel
Prize of Computing). The top three graduate Grand Finalists will
receive an additional $500, $300, and $200. Likewise, the top three
undergraduate Grand Finalists will receive an additional $500, $300,
and $200. All six Grand Finalists will receive Grand Finalist
certificates.

** Eligibility **

The SRC is open to both undergraduate and graduate students. Upon
submission, entrants must be enrolled as a student at their
university.

The abstract must describe the student’s individual research and must
be authored solely by the student. If the work is collaborative with
others and/or part of a larger group project, the abstract should make
clear what the student’s role was and should focus on that portion of
the work. The extended abstract must not exceed 800 words and must not
be longer than 2 pages. The reference list does not count towards
these limits. To submit an abstract, please register through the
submission page and follow the instructions. Abstracts submitted after
the deadline may be considered at the committee's discretion, but only
after decisions have been made on all abstracts submitted before the
deadline. If you have any problems, don't hesitate to contact the
competition chair. More information about the submission process can
be found online at: http://www.icfpconference.org/icfp2012/src.html


** Important Dates **

Deadline for submission: June 29th
Notification of acceptance: July 8th

** Selection Committee **

Koen Claessen, Chalmers University of Technology
Robby Findler (ICFP Program chair), Northwestern University
Ken Friis Larsen, IT University of Copenhangen
Jacques Garrigue, Nagoya University
Doaitse Swierstra (Chair), Utrecht University

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Martin Odersky on "What's wrong with Monads"

2012-06-25 Thread Anton Kholomiov
The class you're looking for is Applicative. The (<*>) operator handles
application of "effectful" things to "effectful" things, whereas (<$>)
handles the application of non-"effectful" things to "effectful" things.
This situation is interesting because it highlights the fact that there is
a distinction between the meaning of whitespace between function and
argument vs the meaning of whitespace between argument and argument.


`Applicative` is not enough for monads.
`Applicative` is like functor only for functions
with many arguments. It's good for patterns:

(a -> b -> c -> d) -> (m a -> m b -> m c -> m d)

Monads are good for patterns

(a -> b -> c -> m d) -> (m a -> m b -> m c -> m d)

So I can not express it with `Applicative`. My
analogy really breaks down on functions with
several arguments, since as you have pointed out there are
two white spaces. But I like the idea of using
one sign for normal and monadic  and maybe applicative
applications.

Anton
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe