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

2012-06-25 Thread Simon Hengel
Hi Jonathan,

 I'm seeing crazy amounts of slowdown in a ghci session after just a few
 executions of :r (reload). Using :set +r (revert top-level bindings)
 doesn't seem to help.

What version of ghc are you using?

Cheers,
Simon

___
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 12:50, Magicloud Magiclouds
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.

 ___
 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

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


[Haskell-cafe] ANNOUNCE : Leksah 0.12.1.3 (fix for GHCi locking up)

2012-06-25 Thread Hamish Mackenzie
This release fixes a problem where the GHCi integration
would break when the first command set was from the
debug scratch pane.

Source is in Hackage and https://github.com/leksah

Binary Installers
Use ghc --version to work out which one you need.

OS X
http://leksah.org/packages/leksah-0.12.1.3-ghc-7.0.3.dmg
http://leksah.org/packages/leksah-0.12.1.3-ghc-7.0.4.dmg
http://leksah.org/packages/leksah-0.12.1.3-ghc-7.4.1.dmg

Windows
http://leksah.org/packages/leksah-0.12.1.3-ghc-6.12.3.exe
http://leksah.org/packages/leksah-0.12.1.3-ghc-7.0.3.exe
http://leksah.org/packages/leksah-0.12.1.3-ghc-7.0.4.exe
http://leksah.org/packages/leksah-0.12.1.3-ghc-7.4.1.exe



___
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 Chris Dornan
On 24 June 2012 18:46, Alexander Solla alex.so...@gmail.com wrote:


 I sort of see where you're coming from.  But I'm having a hard time seeing
 how this complaint would work with respect to Maybe and the other pure
 monads.  In other words, I suspect the problem you're describing is
 particular to IO and IO-like monads.


Yes this problem is specific to IO-based functions. If you didn't know
anything about monads yet would have written a Maybe/Either function then
the types are identical to the monadic formulation, and the monadic
framework in this case is just helping you to structure everything. Unless
this structucture is obscuring or confusing matters (and I don't see it)
its difficult to imagine any objection here.


 I don't know SML.  How is our list monadic and theirs not?  In
 particular, how is Haskell forcing the reification while SML does not?


In SML you can put side-effecting computaions in 'pure' functions --
functions whose type doesn't reveal that there are side effects. In Haskell
terms, every function is actually in the IO monad -- or every function is
given carte blanche to use unsafePerformIO depending upon how you look at
it. In semantic terms it is really a case of the former; from a programming
perspecive it is more like the latter; Standard ML is strict and I am
pretty sure this is only practical in a strict language. It is (IMHO)
deeply horrible, and possibly justifiable before monadic I/O was invented
(but not for me).

I am not advocating doing this (at all) but using it to illustrate a point.
In standard ML you can start doing effect-based things inside a function
without having to alter its type and they type of everything that uses it,
and so on.

Chris
___
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 Arlen Cuss
 In standard ML you can start doing effect-based things inside a function 
 without having to alter its type and they type of everything that uses it, 
 and so on.
This in turn causes a break-down in the type-system where weak type variables 
are introduced.  We can see the pathological case for that here: 
http://www.cs.washington.edu/education/courses/cse505/00au/lectures/13-refs.txt

This makes regular things like curried function compositions unusable, because 
their polymorphicness goes away!  Such is the result of not encapsulating 
side-effects.

—Arlen

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


Re: [Haskell-cafe] Request for optimizing help.

2012-06-25 Thread Johannes Waldmann
First, why do you think your code is non-optimal?

you don't show your main program, so we don't know what you're measuring.

Just by looking at some types (and not analysing the algorithm):

11 data FilterState a = FilterState {
14   , taps :: [a] -- current delay tap stored values

the State really is taps only. (as  and  bs don't change ?)
so taps should be separate.

25         newTaps = wk : init (taps s)

init could be expensive (linear in the list length)
(but you have linear cost elsewhere, so maybe it does not hurt)

Use some different sequence type (instead of list)?
It seems you actually want a strict sequence (while (:) is lazy)
of strict values.

31 runFilter :: Kernel a - FilterState a - [a] - IO ([a], FilterState a)

why IO? there's no IO in the implementation. it looks like a simple fold.

the type is polymorphic, so ghc needs to be able 
to inline the dictionary arguments. (I think that it means that
it wants to see all the code when compiling main, but I'm not sure.
Experts can tell by studing  -ddump-simpl  output.)




___
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 Chris Dornan
On 24 June 2012 22:38, Tony Morris tonymor...@gmail.com wrote:

 **
 Odersky is repeatedly wrong on this subject and specifically for the claim
 that you quote, the only response is simply not true.


My point is this.

   1. The monadic approach to effects reifies functions into those that are
   'pure' and those that perform I/O -- you can tell which is which from the
   type.
   2. If you discover deep inside a function that you need after all to
   perform some I/O then the type of the function changes, and the type of
   everything that uses it changes, all the way back to the I/O trunk. The way
   these changed parts fit together changes radically. There is here an
   in-built instability here that is not *in itself* desirable.
   3. To compare, if you suddenly find you need to use a sin function
   deeply in a package providing pure trigonometric functions you don't have
   to rebuild everything. Likewise, if I discover I need to copy a file in an
   I/O system then this is not a big deal. Discovering (in Haskell) that you
   need to perfrom I/O somewhere that you thought didn't need to perform I/O
   is not like this.
   4. This instability, is in itself regretable I think. I think it is
   regreatble in the way that having to debug code is regretable, or having to
   write code at all is regreatable (why doesn't it write itself?). Its the
   cost of doing business.

Of couse Martin Odersky may have meant something else but this is the only
way I can make sense of it.

Making sense of part of what is being said and agreeing with it are quite
different -- never mind agreeing with the wider point.

Chris
___
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


[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] 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
ivan.miljeno...@gmail.com wrote:
 On 25 June 2012 12:50, Magicloud Magiclouds
 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.

 ___
 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


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 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
 ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com) wrote:
  On 25 June 2012 12:50, Magicloud Magiclouds
  magicloud.magiclo...@gmail.com (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] 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 waldm...@imn.htwk-leipzig.de

 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 Ivan Lazar Miljenovic
On 25 June 2012 19:04, Arlen Cuss 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.

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
 ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com) wrote:
  On 25 June 2012 12:50, Magicloud Magiclouds
  magicloud.magiclo...@gmail.com (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] 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
ivan.miljeno...@gmail.com wrote:
 On 25 June 2012 19:04, Arlen Cuss 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.

 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
 ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com) wrote:
  On 25 June 2012 12:50, Magicloud Magiclouds
  magicloud.magiclo...@gmail.com (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] 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 olshansk...@gmail.comwrote:

 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 waldm...@imn.htwk-leipzig.de

 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
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 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
 ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com) wrote:
  On 25 June 2012 12:50, Magicloud Magiclouds
  magicloud.magiclo...@gmail.com (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] 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
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 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
 ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com) wrote:
  On 25 June 2012 12:50, Magicloud Magiclouds
  magicloud.magiclo...@gmail.com (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 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
 magicloud.magiclo...@gmail.com (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 a...@len.me 
  (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
ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com) wrote:
 On 25 June 2012 12:50, Magicloud Magiclouds
 magicloud.magiclo...@gmail.com 
 (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] 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 lbo...@gmail.com

 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 
 olshansk...@gmail.comwrote:

 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 waldm...@imn.htwk-leipzig.de

 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 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 olshansk...@gmail.comwrote:

 In my test it works ~20% faster than s2 and ~20% slower than s1.
 Did you use -O2 flag?


 2012/6/25 Lorenzo Bolla lbo...@gmail.com

 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 olshansk...@gmail.com
  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 waldm...@imn.htwk-leipzig.de

 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 Duncan Coutts
On 25 June 2012 02:04, Johannes Waldmann waldm...@imn.htwk-leipzig.de 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] About using type to do type alias.

2012-06-25 Thread Ivan Lazar Miljenovic
On 25 June 2012 20:00, Magicloud Magiclouds
magicloud.magiclo...@gmail.com 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
 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 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
 ivan.miljeno...@gmail.com (mailto:ivan.miljeno...@gmail.com) wrote:
  On 25 June 2012 12:50, Magicloud Magiclouds
  magicloud.magiclo...@gmail.com (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] 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 anton.kholom...@gmail.com

 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] ghci session slows down over time.

2012-06-25 Thread Ketil Malde
Jonathan Geddes geddes.jonat...@gmail.com 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] 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 aditya.si...@gmail.com 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] Origin of Delimited Continuation Operators

2012-06-25 Thread Stephen Tetley
On 25 June 2012 18:02, Stephen Tetley stephen.tet...@gmail.com 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


[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] 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 ke...@malde.org wrote:

 Jonathan Geddes geddes.jonat...@gmail.com 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 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 agocor...@gmail.comwrote:

 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 anton.kholom...@gmail.com

 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


[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] 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-bananahttp://www.haskell.org/haskellwiki/Reactive-banana

 and Stackoverflow

  
 http://stackoverflow.com/**questions/tagged/frphttp://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.pdfhttp://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#**documentationhttp://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-cafehttp://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 haskell-cafe%2bunsubscr...@googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/haskell-cafe?hl=enhttp://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


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

2012-06-25 Thread MightyByte
Jonathan Geddes geddes.jonathan at 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] Hackage 2 maintainership

2012-06-25 Thread Jeremy Shaw
On Wed, Jun 20, 2012 at 11:06 AM, Ben Gamari bgamari.f...@gmail.com 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