[Haskell-cafe] Understanding GHC allocations
I'm trying to optimize the following program: http://github.com/feuerbach/particles/blob/303c8a17c9b732e22457b5409bdce4b7520be94a/run.hs Of course general suggestions are welcome (BTW I'm going to give a try to vector), but currently I'm concerned with two questions: 1. Heavy allocations in 'distance' function. Here is (part of) the profile: COST CENTRE MODULE%time %alloc ticks bytes d2Main9.0 22.0290 6 d Main8.6 65.9278 18 d1Main7.5 11.0242 29970 >From reading core I got the impression that everything is strict & unboxed. Perhaps this is related to creating some closures? How to get rid of those allocations? 2. Again from reading the core I learned that although 'l' and other constants are inlined, their type is boxed Double. This makes sense since CAFs are evaluated on demand, but obviously in this particular case it does not make sense, so can I somehow make them unboxed? -- Roman I. Cheplyaka :: http://ro-che.info/ "Don't let school get in the way of your education." - Mark Twain ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Understanding GHC allocations
* Roman Cheplyaka [2010-06-17 12:40:59+0300] > I'm trying to optimize the following program: > http://github.com/feuerbach/particles/blob/303c8a17c9b732e22457b5409bdce4b7520be94a/run.hs > > Of course general suggestions are welcome (BTW I'm going to give a try > to vector), but currently I'm concerned with two questions: > > 1. Heavy allocations in 'distance' function. Here is (part of) the profile: > > COST CENTRE MODULE%time %alloc ticks bytes > > d2Main9.0 22.0290 6 > d Main8.6 65.9278 18 > d1Main7.5 11.0242 29970 > > >From reading core I got the impression that everything is strict & > unboxed. Perhaps this is related to creating some closures? How to get > rid of those allocations? > > 2. Again from reading the core I learned that although 'l' and other > constants are inlined, their type is boxed Double. This makes sense > since CAFs are evaluated on demand, but obviously in this particular > case it does not make sense, so can I somehow make them unboxed? Forgot to mention, I'm using ghc 6.12.1, compiling with -O2. -- Roman I. Cheplyaka :: http://ro-che.info/ "Don't let school get in the way of your education." - Mark Twain ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaskellWiki and Wikipedia
I mean that a link [[X]] leads to HaskellWiki if X exists in HaskellWiki and to Wikipedia otherwise. Interwiki links requires to change all occurrences of [[X]] when X is created. |[[wikipedia:|{{PAGENAME}}|]]| may be handy on existing pages, it provides a link to additional material. On 17.06.10 03:11, Jason Dagit wrote: Both use the mediawiki engine. I know at one point mediawiki supported a notion of "interwiki" links. Perhaps this feature still exists and would give a way for us to more naturally link to wikipedia articles? http://www.mediawiki.org/wiki/Help:Links#Interwiki_links -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaskellWiki and Wikipedia
I do not agree. They are not confused by other languages, they treat all languages as born equal. Do not forget, mathematics is the common source of knowledge for all programmers, creating our separate source of knowledge leads to isolationism and narrow-minded vision. If my words are too vague — "catamorphism" and "F-algebra" belong to mathematics, not to Haskell. Maybe Wikipedia articles are bad because they are provided by community — then HaskellWiki will suffer likewise. :( On 16.06.10 23:19, Ketil Malde wrote: Edward Kmett writes: I realize that this is addressing the symptom, not the cause I'm not so sure Wikipedia is a good source of information for this. I've tried to read some of their articles on e.g. type systems or generic programming, but they tend to be confused by other languages and their communities using these terms to mean different things. So I think it is better to build on the HaskellWiki where the words can mean what we want them to. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
On Wed, 16 Jun 2010, Marc Weber wrote: Hi Aditya Siram, - maybe shell scripting: running ghci takes longer than starting bash. Compiling is not always an option because executables are bigger than shell scripts or C executables Is Hugs better in this respect? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How does one get off haskell?
Hi list, I'm facing a really tough problem. About 3 years ago I stopped doing freelance and quite nicely paid projects in Java, PHP and C#. Now I'm dire straits, again, and need to get back into the project market which seems to have picked up again, quite a lot of projects out there and it looks like I could ask again for decent rates. (I personally call them compensation because I never ever enjoyed doing Java etc. but the money was good.) Anyway the problem is that I am totally reluctant to code in anything else but haskell. It has always been a problem to me getting up early in the morning, taking a train to work and coming back in the evening totally exhausted. But I think I could manage that again, at least for 3 or 6 months and then my bank account will be fine again and I can take it easy for another year or so. But this time all this is much harder. I really cannot see myself writing such huge amounts of code over and over again not doing much, well you know the story. BTW this is not meant as a fun post, I'm actually quite serious, ie. I need money, only way of getting it is doing Java, C# or PHP. So how does one get off haskell? Are there people in similar situations that have managed? How did you do it? Günther ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
On Thu, Jun 17, 2010 at 3:38 PM, Henning Thielemann wrote: > On Wed, 16 Jun 2010, Marc Weber wrote: >> Hi Aditya Siram, >> - maybe shell scripting: running ghci takes longer than starting bash. >> Compiling is not always an option because executables are bigger than >> shell scripts or C executables > Is Hugs better in this respect? Or JHC ? JHC's executables are small. David. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How does one get off haskell?
Become the farmer. The life in village brings advantage for health more. (I too am serious. :) ) 2010/6/17 Günther Schmidt : > Hi list, > > I'm facing a really tough problem. About 3 years ago I stopped doing > freelance and quite nicely paid projects in Java, PHP and C#. > > Now I'm dire straits, again, and need to get back into the project market > which seems to have picked up again, quite a lot of projects out there and > it looks like I could ask again for decent rates. (I personally call them > compensation because I never ever enjoyed doing Java etc. but the money was > good.) > > Anyway the problem is that I am totally reluctant to code in anything else > but haskell. It has always been a problem to me getting up early in the > morning, taking a train to work and coming back in the evening totally > exhausted. But I think I could manage that again, at least for 3 or 6 months > and then my bank account will be fine again and I can take it easy for > another year or so. > > But this time all this is much harder. I really cannot see myself writing > such huge amounts of code over and over again not doing much, well you know > the story. > > BTW this is not meant as a fun post, I'm actually quite serious, ie. I need > money, only way of getting it is doing Java, C# or PHP. > > So how does one get off haskell? Are there people in similar situations that > have managed? How did you do it? > > Günther > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Никитин Лев. n...@lab321.ru, leon.v.niki...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How does one get off haskell?
2010/6/17 Günther Schmidt : > Anyway the problem is that I am totally reluctant to code in anything else > but haskell. It has always been a problem to me getting up early in the You're not alone. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Understanding GHC allocations
On Thursday 17 June 2010 11:43:09, Roman Cheplyaka wrote: > * Roman Cheplyaka [2010-06-17 12:40:59+0300] > > > I'm trying to optimize the following program: > > http://github.com/feuerbach/particles/blob/303c8a17c9b732e22457b5409bd > >ce4b7520be94a/run.hs > > > > Of course general suggestions are welcome (BTW I'm going to give a try > > to vector), but currently I'm concerned with two questions: > > > > 1. Heavy allocations in 'distance' function. Here is (part of) the > > profile: > > > > COST CENTRE MODULE%time %alloc ticks bytes > > > > d2Main9.0 22.0290 6 > > d Main8.6 65.9278 18 > > d1Main7.5 11.0242 29970 > > I suspect the distance function is not what you intended, distance :: Double -> Double -> Double distance !x1 !x2 = {-# SCC "min" #-} min d1 d2 where d = {-# SCC "d" #-} x1 - x2 d1 = {-# SCC "d1" #-} abs d d2 = {-# SCC "d2" #-} abs $ l - d that would give distance 0.2 24.8 = 24.6, while the wrapping suggests that it should be 0.4, so in d2, it should be d1 instead of d. Either way, both d and d1 are <= 25, so the 'abs' in d2 is superfluous, removing that alone reduces the allocations drastically and the running time by ~40% (astonishingly, not in the profiling version, I suspect it's because profiling needs a few registers so that there aren't enough left for the loops on my box). Further, if you export only main from the module, you allow GHC to be more aggressive with optimising. On my box, that leads to more allocation again because there aren't enough registers, but things become a little faster. Also, a few more bangs here and there plus a couple of INLINE and UNPACK pragmas speed things up, the (on my box) fastest combination I've found is attached, it has the same semantics for distance as the original code, changing distance to what I believe it should be unfortunately slows it down significantly. On my box, I get a further big speedup by compiling with -O2 -fexcess-precision -fvia-C -optc-O3 > > >From reading core I got the impression that everything is strict & > > > > unboxed. Not everything, there lurk a few boxed Doubles e.g. in average. > > Perhaps this is related to creating some closures? How to get > > rid of those allocations? > > Do you need to? Sometimes an allocating loop is faster than a non- allocating one (of course, if you have enough registers for the allocating loop to run entirely in registers, it'll be much faster still). IMO, the important criteria are time and resident memory, not allocation. > > 2. Again from reading the core I learned that although 'l' and other > > constants are inlined, their type is boxed Double. This makes sense > > since CAFs are evaluated on demand, but obviously in this particular > > case it does not make sense, so can I somehow make them unboxed? Putting bangs in the loops where they are used likely uses the unboxed values; not exporting them too. > > Forgot to mention, I'm using ghc 6.12.1, compiling with -O2. {-# LANGUAGE BangPatterns #-} module Main (main) where import System.Random import Text.Printf import Data.List import System.IO {-# INLINE r #-} r = 1 {-# INLINE r2 #-} r2 = r*r n = 1000 time = 100 {-# INLINE l #-} l = 25 {-# INLINE h #-} h = 0.01 data Point = Point {-# UNPACK #-} !Double {-# UNPACK #-} !Double data Particle = Particle { point :: !Point, angle :: !Double } -- point, angle {-# INLINE distance #-} distance :: Double -> Double -> Double distance !x1 !x2 | x1 < x2 = x2-x1 | otherwise = let !d = x1-x2 in min d (l-d) -- distance !x1 !x2 = {-# SCC "min" #-} min d1 d2 -- where -- !d = {-# SCC "d" #-} x1 - x2 -- !d1 = {-# SCC "d1" #-} abs d -- !d2 = {-# SCC "d2" #-} abs $ l - d {-# INLINE pointsAreClose #-} pointsAreClose :: Point -> Point -> Bool pointsAreClose (Point x1 y1) (Point x2 y2) = sqr (distance x1 x2) + sqr (distance y1 y2) < r2 --where sqr !x = x * x {-# INLINE sqr #-} sqr :: Double -> Double sqr !x = x*x {-# INLINE average #-} average :: [Double] -> Double average list = -- let (!s,!n) = foldl' (\(!s,!n) x -> (s+x,n+1)) (0,0) list in s / n case foldl' (\(!s, !n) !x -> (s + x, n + 1)) (0.0, 0.0) list of (!s, !n) -> s / n {-# INLINE wrap #-} wrap :: Double -> Double wrap x | x < 0 = x + l | x > l = x - l | otherwise = x makeStep :: [Particle] -> Double -> [Particle] makeStep allParticles dt = map (makeStep1 dt allParticles) allParticles makeStep1 :: Double -> [Particle] -> Particle -> Particle makeStep1 dt allParticles particle = updateParticle dt particle newAngle where !newAngle = average . map angle . filter (pointsAreClose (point particle) . point) $ allParticles updateParticle dt (Particle (Point x0 y0) _) newAngle = Particle (Point x1 y1) newAngle where x1 = wrap $ x0 + cos newAngle * dt y1 = wrap $ y0 + sin newAngle * dt create = zipWith3 (\x y a -> Par
Re: [Haskell-cafe] How does one get off haskell?
Maybe you should trying getting on Scala or Clojure projects ? Though they aren't many of them for now :( 2010/6/17 Günther Schmidt > Hi list, > > I'm facing a really tough problem. About 3 years ago I stopped doing > freelance and quite nicely paid projects in Java, PHP and C#. > > Now I'm dire straits, again, and need to get back into the project market > which seems to have picked up again, quite a lot of projects out there and > it looks like I could ask again for decent rates. (I personally call them > compensation because I never ever enjoyed doing Java etc. but the money was > good.) > > Anyway the problem is that I am totally reluctant to code in anything else > but haskell. It has always been a problem to me getting up early in the > morning, taking a train to work and coming back in the evening totally > exhausted. But I think I could manage that again, at least for 3 or 6 months > and then my bank account will be fine again and I can take it easy for > another year or so. > > But this time all this is much harder. I really cannot see myself writing > such huge amounts of code over and over again not doing much, well you know > the story. > > BTW this is not meant as a fun post, I'm actually quite serious, ie. I need > money, only way of getting it is doing Java, C# or PHP. > > So how does one get off haskell? Are there people in similar situations > that have managed? How did you do it? > > Günther > > ___ > 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] How does one get off haskell?
2010/6/17 Günther Schmidt : > Hi list, > > I'm facing a really tough problem. About 3 years ago I stopped doing > freelance and quite nicely paid projects in Java, PHP and C#. > > Now I'm dire straits, again, and need to get back into the project market > which seems to have picked up again, quite a lot of projects out there and > it looks like I could ask again for decent rates. (I personally call them > compensation because I never ever enjoyed doing Java etc. but the money was > good.) > > Anyway the problem is that I am totally reluctant to code in anything else > but haskell. It has always been a problem to me getting up early in the > morning, taking a train to work and coming back in the evening totally > exhausted. But I think I could manage that again, at least for 3 or 6 months > and then my bank account will be fine again and I can take it easy for > another year or so. > > But this time all this is much harder. I really cannot see myself writing > such huge amounts of code over and over again not doing much, well you know > the story. > > BTW this is not meant as a fun post, I'm actually quite serious, ie. I need > money, only way of getting it is doing Java, C# or PHP. > > So how does one get off haskell? Are there people in similar situations that > have managed? How did you do it? Perhaps Galois is hiring? :-) - Dave > > Günther > > ___ > 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] How does one get off haskell?
Haven't tried this, but maybe it can help you... Online freelance jobs search engine, I'ts supposed to be good... http://www.donanza.com/ Good Luck $$$, Hector Guilarte Enviado desde mi dispositivo movil BlackBerry. -Original Message- From: Günther Schmidt gue.schm...@web.de Date: Thu, 17 Jun 2010 15:55:15 To: Subject: [Haskell-cafe] How does one get off haskell? Hi list, I'm facing a really tough problem. About 3 years ago I stopped doing freelance and quite nicely paid projects in Java, PHP and C#. Now I'm dire straits, again, and need to get back into the project market which seems to have picked up again, quite a lot of projects out there and it looks like I could ask again for decent rates. (I personally call them compensation because I never ever enjoyed doing Java etc. but the money was good.) Anyway the problem is that I am totally reluctant to code in anything else but haskell. It has always been a problem to me getting up early in the morning, taking a train to work and coming back in the evening totally exhausted. But I think I could manage that again, at least for 3 or 6 months and then my bank account will be fine again and I can take it easy for another year or so. But this time all this is much harder. I really cannot see myself writing such huge amounts of code over and over again not doing much, well you know the story. BTW this is not meant as a fun post, I'm actually quite serious, ie. I need money, only way of getting it is doing Java, C# or PHP. So how does one get off haskell? Are there people in similar situations that have managed? How did you do it? Günther ___ 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] How does one get off haskell?
Hi all, I was afraid of that. The tenor here is "there is no way to get off haskell" so either do woodwork or try to get a haskell job. :( Günther ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
On Jun 17, 2010, at 10:17 , David Virebayre wrote: On Thu, Jun 17, 2010 at 3:38 PM, Henning Thielemann wrote: On Wed, 16 Jun 2010, Marc Weber wrote: Hi Aditya Siram, - maybe shell scripting: running ghci takes longer than starting bash. Compiling is not always an option because executables are bigger than shell scripts or C executables Is Hugs better in this respect? Or JHC ? JHC's executables are small. Get shared libraries working, and this becomes a non-issue; you're not buying anything disk-wise if the file is smaller than the block size (does any production fs use fragments any more? I know Linux filesystems don't). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH PGP.sig Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell-beginners] Re: Accounting Engine in Haskell
Hi, > Keep in mind that you have to invest some time in learning Haskell > before you can reap the benefits. For an example of the latter, see also > > Paul Hudak, Mark P. Jones. > Haskell vs. Ada vs. C++ vs. Awk vs. ..., > An Experiment in Software Prototyping Productivity > http://haskell.org/papers/NSWC/jfp.ps This paper was very interesting to me. Does anyone know if the full source code for the Haskell prototype is available somewhere? Patrick -- = Patrick LeBoutillier Rosemère, Québec, Canada ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell-beginners] Re: Accounting Engine in Haskell
On 17 June 2010 16:12, Patrick LeBoutillier wrote: > This paper was very interesting to me. Does anyone know if the full source > code > for the Haskell prototype is available somewhere? Chapter 8 of Paul Hudak's School of Expression contains a version of the "region algebra", there's also an ML version by Samuel Kamin where the region combinators generate C++ code: Samuel Kamin - Standard ML as a Meta-Programming Language: http://loome.cs.uiuc.edu/pubs.html http://loome.cs.uiuc.edu/pubs/ml-meta.pdf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: How does one get off haskell?
If you're willing to use "Haskell" as a synonym for FP of sorts, you can now get cool jobs writing Scala -- e.g. Sony uses it to manage all of their disk farms; Clojure is awesome, although very different (dynamic and macro); and Jane Street is always hiring in New York, London and Tokyo doing OCaml. The JVM languages are really cool in the way they can work anywhere Java can, including the Google App Engine, and there're now startups exploiting that. F# is truly an amazing feat, now fully supported by MSFT, so even there you have a viable and sane alternative to boilerplate. #scala is full of Haskell lurkers. They bring a lambdabot with them to annoy Java people with what the types of things should be. But I'd say, with such attitude the best thing to do is to gang up with a few like-minded warriors and form a startup. This is what these folks had done: http://www.infoq.com/articles/deadline-clojure-appengine I think this is the best model. Cheers, Alexy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: What is Haskell unsuitable for?
At this very moment I'm struggling with fitting a huge graph of Twitter communications into a Haskell program. Apparently it gets into a loop freeing memory. As I suspected, JVM garbage collector got more testing than Haskell at this scale; since not many people load it up as much, it may be less tested. The memory behavior apparently requires tweaking -A and -H in some ways not right away obvious. I'm still new to Haskell, so perhaps with more profiling/tuning experience it would have been easier, but so far Clojure is more predictable -- even though Haskell beats it on a smaller data set, I get a linear resource consumption with Clojure while Haskell explodes. I'd say at this point it's not prime time for large-scale data mining on a single box. -- Alexy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Understanding GHC allocations
On 17.06.10 12:40, Roman Cheplyaka wrote: > From reading core I got the impression that everything is strict& unboxed. Perhaps this is related to creating some closures? How to get rid of those allocations? Yes, "distance" creates a closure of type @Double -> Double# -> Double@ which is obviously not necessary. I do not know why. 2. Again from reading the core I learned that although 'l' and other constants are inlined, their type is boxed Double. This makes sense since CAFs are evaluated on demand, but obviously in this particular case it does not make sense, so can I somehow make them unboxed Hmm, I learned from "-ddump-core" that "distance" function uses constant "25.0". There is another way to optimize — make GHC use floating point "abs" processor instruction. Now it uses {{{ abs x | x >= 0.0 = x | otherwise = negateDouble x }}} http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/GHC-Float.html -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: How does one get off haskell?
Another way to be happy is to get a family to support, then any idea of making a quick pfennig with C# and then luxuriating in Rio with a laptop full of Haskell will only work if your company goes public! :) -- Alexy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: What is Haskell unsuitable for?
deliverable: > At this very moment I'm struggling with fitting a huge graph of > Twitter communications into a Haskell program. Apparently it gets > into a loop freeing memory. As I suspected, JVM garbage collector got > more testing than Haskell at this scale; since not many people load it > up as much, it may be less tested. Did you talk to Simon Marlow yet? Unlike the JVM, we provide direct access to the GC developers when you run into trouble. :) -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Understanding GHC allocations
* Daniel Fischer [2010-06-17 16:27:01+0200] > On Thursday 17 June 2010 11:43:09, Roman Cheplyaka wrote: > > * Roman Cheplyaka [2010-06-17 12:40:59+0300] > > > > > I'm trying to optimize the following program: > > > http://github.com/feuerbach/particles/blob/303c8a17c9b732e22457b5409bd > > >ce4b7520be94a/run.hs > > > > > > Of course general suggestions are welcome (BTW I'm going to give a try > > > to vector), but currently I'm concerned with two questions: > > > > > > 1. Heavy allocations in 'distance' function. Here is (part of) the > > > profile: > > > > > > COST CENTRE MODULE%time %alloc ticks bytes > > > > > > d2Main9.0 22.0290 6 > > > d Main8.6 65.9278 18 > > > d1Main7.5 11.0242 29970 > > > > > I suspect the distance function is not what you intended, > distance 0.2 24.8 = 24.6, while the wrapping suggests that it should be > 0.4, so in d2, it should be d1 instead of d. Good catch! :) > Either way, both d and d1 are <= 25, so the 'abs' in d2 is superfluous, Correct > removing that alone reduces the allocations drastically and the running > time by ~40% That's exactly what I'm asking about. 'abs' in C does not require any allocations, does it? So why does it require any allocations in Haskell, assuming we've got no lazyness, typeclass indirection (I assume 'abs' was specialized and inlined) or other high-level features in resulted low-level code? > Further, if you export only main from the module, you allow GHC to be more > aggressive with optimising. On my box, that leads to more allocation again > because there aren't enough registers, but things become a little faster. Good idea indeed. > > > Perhaps this is related to creating some closures? How to get > > > rid of those allocations? > > > > > Do you need to? Sometimes an allocating loop is faster than a non- > allocating one (of course, if you have enough registers for the allocating > loop to run entirely in registers, it'll be much faster still). > > IMO, the important criteria are time and resident memory, not allocation. Maybe, but what bothers me is that I can't answer myself where are those allocation from. What problem do they solve? > > > 2. Again from reading the core I learned that although 'l' and other > > > constants are inlined, their type is boxed Double. This makes sense > > > since CAFs are evaluated on demand, but obviously in this particular > > > case it does not make sense, so can I somehow make them unboxed? > > Putting bangs in the loops where they are used likely uses the unboxed > values; not exporting them too. I'll play with this, thanks. -- Roman I. Cheplyaka :: http://ro-che.info/ "Don't let school get in the way of your education." - Mark Twain ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: What is Haskell unsuitable for?
(Looks like my previous reply didn't go through yet) -- yes, we're working on it! :) Cheers, Alexy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: What is Haskell unsuitable for?
On Jun 17, 12:20 pm, Don Stewart wrote: > Did you talk to Simon Marlow yet? Unlike the JVM, we provide direct > access to the GC developers when you run into trouble. :) Yes -- Simon's very helpful, he showed how to identify the loop and debug it further. Hopefully we'll work together on it to make Haskell more robust for this loads. Generally the community is fantastic and I recommend learning Haskell by doing things while asking questions on the IRC! -- Alexy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] What is Haskell unsuitable for? Dis-functional programming!
:) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] The functional-object style seems to be gaining momentum.
The functional-object style seems to be gaining momentum. Is there any way to convert monads into objects, so that beginners have an easier time with the syntax and thus we can attract more people to the language? :) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for? Dis-functional programming!
On Thu, 17 Jun 2010 13:45:16 -0400 cas...@istar.ca wrote: > :) > Objection! http://hackage.haskell.org/package/BASIC A simplified version of the original BASIC embedded in Haskell. -- Alexey Khudyakov ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
aditya siram wrote: But I wanted to ask people are more experienced with Haskell - what kinds of problems is it unsuited for? Judging by the other thread, "getting hired" might be a valid answer here... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: What is Haskell unsuitable for?
Don Stewart wrote: Did you talk to Simon Marlow yet? Unlike the JVM, we provide direct access to the GC developers when you run into trouble. :) Surely the GHC developers are amoung the busiest people on the planet though... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Mining Twitter data in Haskell and Clojure
I'll work with Simon to investigate the runtime, but would welcome any ideas on further speeding up cafe4. Just a wild guess, but those foldWithKeys make me nervous. The result is strict, the step function tries to be strict, but if you look at the code for Data.IntMap.foldr, it doesn't really give you a handle for propagating that strictness. Unless the foldr definition is inlined into your code, the generic, non-strictly accumulating version might be called. Have you checked that this isn't the case? Also, shouldn't the two foldWithKeys on dm be merged? And, while Maps are strict in their representation, putting them into a non-strict field of a data structure might lose that. As I said, just guessing;-) Claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
No argument there - I'm even afraid to stick it on my resume. At least Clojure can be snuck into the JVM without people noticing - Haskell, unfortunately, is not that shy. -deech On Thu, Jun 17, 2010 at 1:11 PM, Andrew Coppin wrote: > aditya siram wrote: >> >> But I wanted to ask people are more experienced with Haskell - what kinds >> of problems is it unsuited for? > > Judging by the other thread, "getting hired" might be a valid answer here... > > ___ > 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] Re: Mining Twitter data in Haskell and Clojure
Since folks got interested, I've added a doc/ subdirectory (on the "intern" branch) with a PDF defining my karmic social capital mathematically. It is this definition which is faithfully computed both in Clojure and Haskell. I've also added a LICENSE file basically stating that this research is to appear in the proceedings of the European Conference on Complex Systems, Lisbon, September 2010, and should be treated as unpublished research with the paper in copyright but the code under GPL. I.e. if you want to experiment with the definition itself, in addition to making it compute in Haskell, please let me know -- we're always glad to collaborate. The purpose to implement it in a functional language, besides loathing all others, is to enable quick experimentation with the karmic rewards, then running the whole world simulation and seeing who accumulates more social capital. It can also be used in a machine learning approach where it's made to fit an existing ranking function. Thus this computation has to be as fast as possible. -- Alexy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
aditya siram wrote: No argument there - I'm even afraid to stick it on my resume. At least Clojure can be snuck into the JVM without people noticing - Haskell, unfortunately, is not that shy. Oh, I don't know... Few companies will want you to *use* Haskell, but lots of people seemed to be impressed if you say you know how to use it. (Those that know WTF is actually is, anyway...) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
On Thu, Jun 17, 2010 at 01:38:23PM -0500, aditya siram wrote: > > Judging by the other thread, "getting hired" might be a valid answer here... > > > No argument there - I'm even afraid to stick it on my resume. At least > Clojure can be snuck into the JVM without people noticing - Haskell, > unfortunately, is not that shy. "I am sad that I can't use cool languages in the boring, mainstream corporate jobs that are easy to find." If you want to use cool languages, you may have to get a cool job. I know: it's easy to say and harder to accomplish. -- Darrin Chandler| Phoenix BSD User Group | MetaBUG dwchand...@stilyagin.com | http://phxbug.org/ | http://metabug.org/ http://www.stilyagin.com/ | Daemons in the Desert | Global BUG Federation ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Understanding GHC allocations
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Jun 17, 2010, at 12:35 , Roman Cheplyaka wrote: That's exactly what I'm asking about. 'abs' in C does not require any allocations, does it? So why does it require any allocations in Haskell, assuming we've got no lazyness, typeclass indirection (I assume 'abs' was specialized and inlined) or other high-level features in resulted low-level code? Quite a few obvious specializations / rules are missing; you can propose them. Answering your question about the implementation of abs, my guess is that the current definition works for every type (I'm pretty sure C doesn't know what to do with a Data.Ratio). - -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.10 (Darwin) iEYEARECAAYFAkwacCwACgkQIn7hlCsL25XS/wCgvZWVoxZLrIlNywg4ZLA6tEwW UpEAnjTLW5E5EHYcOIu0Eq1Rclh2wxfR =BFE2 -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
On Thu, Jun 17, 2010 at 11:57 AM, Darrin Chandler wrote: > On Thu, Jun 17, 2010 at 01:38:23PM -0500, aditya siram wrote: > > > Judging by the other thread, "getting hired" might be a valid answer > here... > > > > > No argument there - I'm even afraid to stick it on my resume. At least > > Clojure can be snuck into the JVM without people noticing - Haskell, > > unfortunately, is not that shy. > > "I am sad that I can't use cool languages in the boring, mainstream > corporate jobs that are easy to find." > > If you want to use cool languages, you may have to get a cool job. I > know: it's easy to say and harder to accomplish. > > -- > Darrin Chandler| Phoenix BSD User Group | MetaBUG > dwchand...@stilyagin.com | http://phxbug.org/ | > http://metabug.org/ > http://www.stilyagin.com/ | Daemons in the Desert | Global BUG > Federation > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > I would never look at a resume when reviewing people to hire, see an exotic programming language, and draw negative conclusions about that candidate. In fact, I've found that learning to solve problems from different solution spaces in general is a worthwhile mental exercise, and helps one to come up with possibly better solutions in the mainstream languages. Sometimes breadth of experience is a good thing. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Mapping a list of functions
Hello all The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, Related to that is the problem, that the function in map may require more than one argument, so I need to apply it partially to some value(s) first. But what if I want to fix its second and third argument and not its first argument? Can flip help? Thanks -- Martin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
On Jun 17, 2010, at 12:02 PM, Martin Drautzburg wrote: The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, Use Control.Applicative, and the <*> operator. Something like [f, g, h, i, j] <*> pure x (which equals [f x, g x, h x, i x , j x]) Related to that is the problem, that the function in map may require more than one argument, so I need to apply it partially to some value(s) first. But what if I want to fix its second and third argument and not its first argument? Can flip help? I think the <$> operator can help here. Also, don't forget plain old lambda abstraction to abstract over a free variable. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
Martin.Drautzburg: > Hello all > > The standard map function applies a single function to a list of arguments. > But what if I want to apply a list of functions to a single argument. I can > of course write such a function, but I wonder if there is a standard way of > doing this, map ($ 2) [(*2), (+1), (^7)] Cheers, Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
Martin Drautzburg wrote: Hello all The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, The magical incantation you seek is "map ($ x) [fn1, fn2, fn3]". Remember that "$" is a function like any other, and can be curried. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
Martin Drautzburg wrote: The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. So your list of arguments is actually a list of functions. But since functions are first-class values, that shouldn't be a problem. You simply have to write a appropriate function to map over that list of functions: map (\f -> f a b c) listOfFunctions The lambda expression (\f -> f a b c) denotes a function which takes a function f, and applies it to some values a, b and c. That's exactly the function you want to map over the list of functions. Alternatively, you might want to look into list comprehensions: [f a b c | f <- listOfFunctions] Enjoy Haskell! Tillmann ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
listFs = [f1, f2, f3] map ($ x) listFs -- same as [f1 x, f2 x, f3 x] f x y z = ... map (\x -> f x u v) xs On 17 Jun 2010, at 23:02, Martin Drautzburg wrote: Hello all The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, Related to that is the problem, that the function in map may require more than one argument, so I need to apply it partially to some value(s) first. But what if I want to fix its second and third argument and not its first argument? Can flip help? Thanks -- Martin ___ 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] Mapping a list of functions
Martin Drautzburg writes: > Hello all > > The standard map function applies a single function to a list of arguments. > But what if I want to apply a list of functions to a single argument. I can > of course write such a function, but I wonder if there is a standard way of > doing this, > (map ($ 3) [(+2), (*4), (/3)])::[Double] [5.0,12.0,1.0] > Related to that is the problem, that the function in map may require more > than > one argument, so I need to apply it partially to some value(s) first. But > what if I want to fix its second and third argument and not its first > argument? Can flip help? The "pointfree" command-line tool can help you find good short forms for this kind of thing: $ pointfree '\x -> f x 2 3' flip (flip f 2) 3 In this case the explicit (pointed) lambda is simpler so I would usually just use that. G -- Gregory Collins ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
map (\function -> function argument) functions map ($ argument) functions map (\firstArgument -> function firstArgument secondArgument thirdArgument) xs On 17.06.10 22:02, Martin Drautzburg wrote: Hello all The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, Related to that is the problem, that the function in map may require more than one argument, so I need to apply it partially to some value(s) first. But what if I want to fix its second and third argument and not its first argument? Can flip help -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
On Thu, Jun 17, 2010 at 12:01:53PM -0700, David Leimbach wrote: > On Thu, Jun 17, 2010 at 11:57 AM, Darrin Chandler > wrote: > > > On Thu, Jun 17, 2010 at 01:38:23PM -0500, aditya siram wrote: > > > > Judging by the other thread, "getting hired" might be a valid answer > > here... > > > > > > > No argument there - I'm even afraid to stick it on my resume. At least > > > Clojure can be snuck into the JVM without people noticing - Haskell, > > > unfortunately, is not that shy. > > > > "I am sad that I can't use cool languages in the boring, mainstream > > corporate jobs that are easy to find." > > > > If you want to use cool languages, you may have to get a cool job. I > > know: it's easy to say and harder to accomplish. > > > I would never look at a resume when reviewing people to hire, see an exotic > programming language, and draw negative conclusions about that candidate. > In fact, I've found that learning to solve problems from different solution > spaces in general is a worthwhile mental exercise, and helps one to come up > with possibly better solutions in the mainstream languages. > > Sometimes breadth of experience is a good thing. I agree. On the (employee) flip side, I'd rather go work for someone who has views like you mention, regardless of language in use. -- Darrin Chandler| Phoenix BSD User Group | MetaBUG dwchand...@stilyagin.com | http://phxbug.org/ | http://metabug.org/ http://www.stilyagin.com/ | Daemons in the Desert | Global BUG Federation ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Understanding GHC allocations
On 17.06.10 19:12, Roman Beslik wrote: On 17.06.10 12:40, Roman Cheplyaka wrote: > From reading core I got the impression that everything is strict& unboxed. Perhaps this is related to creating some closures? How to get rid of those allocations? Yes, "distance" creates a closure of type @Double -> Double# -> Double@ which is obviously not necessary. I do not know why. "-funfolding-use-threshold=7" removes that closure. -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: How does one get off haskell?
Günther Schmidt web.de> writes: > > So how does one get off haskell? Are there people in similar situations > that have managed? How did you do it? > > Günther > Same feelings here. I work in a company that uses C++/Java and the best I could manage was to use Haskell for prototyping and then deliver in Java. This worked out twice so far. The downside is having to translate it later. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: How does one get off haskell?
Excerpts from Paul Lotti's message of Thu Jun 17 15:33:30 -0400 2010: > Same feelings here. I work in a company that uses C++/Java and the best I > could > manage was to use Haskell for prototyping and then deliver in Java. This > worked > out twice so far. The downside is having to translate it later. *Shudders at the though.* Must be a what, x10 size blow-up? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: How does one get off haskell?
>> So how does one get off haskell? Are there people in similar situations >> that have managed? How did you do it? I used to get annoyed about all the java boilerplate and awkwardness. But then I learned that if I relax and stop thinking so much about the aesthetics of what I'm writing, I can just let my fingers go on typing without having to think too much. Yes, it would have been shorter and more graceful in more capable languages, but I would have had to think more about how to factor things or apply the right abstractions. Ultimately the problems to be solved are the same, it's just that java and c++ give you a lot of padding where you're writing boilerplate and workarounds for not having closures, monadic values, a nice type system, etc. It could be relaxing in the same way that playing 3rd trombone could be: you still get to play technical music every once and a while, but you also get a lot of downtime to count rests and listen to the music, or play whole notes. There is a pleasure in that, even if it's not the same as when you're in the 1st violin section. Music is still being made, problems are still getting solved. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Using Hint with a socket server
I'm trying to receive small segments of Haskell code over a socket, and be able to evaluate them in real time in GHCI. I've already downloaded Hint and have run the test code, and it's working great. I'm also using the socket server code from Ch.27 of "Real World Haskell" and that is working well also. directly below is the function from the socket server code that handles the incoming messages. Instead of doing this: "putStrLn msg"... I want to send whatever is captured in "msg" to the GHC interpreter that is used in the Hint code, something like this: "eval msg". I'm not sure how to combine both of these functionalities to get them to work with each other.. -- A simple handler that prints incoming packets plainHandler :: HandlerFunc plainHandler addr msg = putStrLn msg Below is the full code for the socket server, then below that is "SomeModule" used in the Hint example test below that. -- file: ch27/syslogserver.hs import Data.Bits import Network.Socket import Network.BSD import Data.List type HandlerFunc = SockAddr -> String -> IO () serveLog :: String -- ^ Port number or name; 514 is default -> HandlerFunc -- ^ Function to handle incoming messages -> IO () serveLog port handlerfunc = withSocketsDo $ do -- Look up the port. Either raises an exception or returns -- a nonempty list. addrinfos <- getAddrInfo (Just (defaultHints {addrFlags = [AI_PASSIVE]})) Nothing (Just port) let serveraddr = head addrinfos -- Create a socket sock <- socket (addrFamily serveraddr) Datagram defaultProtocol -- Bind it to the address we're listening to bindSocket sock (addrAddress serveraddr) -- Loop forever processing incoming data. Ctrl-C to abort. procMessages sock where procMessages sock = do -- Receive one UDP packet, maximum length 1024 bytes, -- and save its content into msg and its source -- IP and port into addr (msg, _, addr) <- recvFrom sock 1024 -- Handle it handlerfunc addr msg -- And process more messages procMessages sock -- A simple handler that prints incoming packets plainHandler :: HandlerFunc plainHandler addr msg = putStrLn msg -- main = serveLog "8008" plainHandler module SomeModule(g, h) where f = head g = f [f] h = f import Control.Monad import Language.Haskell.Interpreter main :: IO () main = do r <- runInterpreter testHint case r of Left err -> printInterpreterError err Right () -> putStrLn "that's all folks" -- observe that Interpreter () is an alias for InterpreterT IO () testHint :: Interpreter () testHint = do say "Load SomeModule.hs" loadModules ["SomeModule.hs"] -- say "Put the Prelude, Data.Map and *SomeModule in scope" say "Data.Map is qualified as M!" setTopLevelModules ["SomeModule"] setImportsQ [("Prelude", Nothing), ("Data.Map", Just "M")] -- say "Now we can query the type of an expression" let expr1 = "M.singleton (f, g, h, 42)" say $ "e.g. typeOf " ++ expr1 say =<< typeOf expr1 -- say $ "Observe that f, g and h are defined in SomeModule.hs, " ++ "but f is not exported. Let's check it..." exports <- getModuleExports "SomeModule" say (show exports) -- say "We can also evaluate an expression; the result will be a string" let expr2 = "length $ concat [[f,g],[h]]" say $ concat ["e.g. eval ", show expr1] a <- eval expr2 say (show a) -- say "Or we can interpret it as a proper, say, int value!" a_int <- interpret expr2 (as :: Int) say (show a_int) -- say "This works for any monomorphic type, even for function types" let expr3 = "\\(Just x) -> succ x" say $ "e.g. we interpret " ++ expr3 ++ " with type Maybe Int -> Int and apply it on Just 7" fun <- interpret expr3 (as :: Maybe Int -> Int) say . show $ fun (Just 7) -- say "And sometimes we can even use the type system to infer the expected type (eg Maybe Bool -> Bool)!" bool_val <- (interpret expr3 infer `ap` (return $ Just False)) say (show $ not bool_val) -- say "Here we evaluate an expression of type string, that when evaluated (again) leads to a string" res <- interpret "head $ map show [\"Worked!\", \"Didn't work\"]" infer >>= flip interpret infer say res say :: String -> Interpreter () say = liftIO . putStrLn printInterpreterError :: InterpreterError -> IO () printInterp
Re: [Haskell-cafe] The functional-object style seems to be gaining momentum.
cas...@istar.ca writes: > The functional-object style seems to be gaining momentum. > Is there any way to convert monads into objects, so that beginners > have an easier time with the syntax and thus we can attract more > people to the language? I seriously have no idea what you're talking about here. What is the "functional-object style" and why would we want to convert monads into objects? Anyway, have a look at: * http://www.timber-lang.org/ * http://en.wikipedia.org/wiki/O%27Haskell (homepage link seems down) * http://homepages.cwi.nl/~ralf/OOHaskell/ * http://www.haskell.org/haskellwiki/The_Monad.Reader/Issue3/Functional_Programming_vs_Object_Oriented_Programming etc. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
If you want to use cool languages, you may have to get a cool job. I know: it's easy to say and harder to accomplish. Most functional languages (e.g. Lisp, Haskell, ...) have a challenging time in industry since they require some savvy with multiple levels of higher abstractions and some savvy with mathematical ideas and some savvy with functional algorithms and data structures. Also, your manager has probably come up through the technical ranks on his/her OOA/OOD/OOP skills and sees you as a young (or not) upstart trying to show off. :) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] coming soon: ICFP programming contest 2010
http://icfpcontest.org/2010/ will start roughly 12 hours from now. 2210222201011220101002200112200220010 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: How does one get off haskell?
At CREATE-NET we're hiring Haskellers. If you fancy working in Trento (Italy) and you have experience, apply here. Try these trivial questions http://hpaste.org/fastcgi/hpaste.fcgi/view?id=26317 The question list doesn't indicate expertise but it does filter out newbies. Don't bother if you struggle with these. Send me your CV and links to or tarballs of nontrivial (e.g. >500~ LoC) Haskell projects. Web experience a plus. SCM (Git) experience a plus. On 17 June 2010 22:27, Evan Laforge wrote: >>> So how does one get off haskell? Are there people in similar situations >>> that have managed? How did you do it? > > I used to get annoyed about all the java boilerplate and awkwardness. > But then I learned that if I relax and stop thinking so much about the > aesthetics of what I'm writing, I can just let my fingers go on typing > without having to think too much. Yes, it would have been shorter and > more graceful in more capable languages, but I would have had to think > more about how to factor things or apply the right abstractions. > > Ultimately the problems to be solved are the same, it's just that java > and c++ give you a lot of padding where you're writing boilerplate and > workarounds for not having closures, monadic values, a nice type > system, etc. It could be relaxing in the same way that playing 3rd > trombone could be: you still get to play technical music every once > and a while, but you also get a lot of downtime to count rests and > listen to the music, or play whole notes. There is a pleasure in > that, even if it's not the same as when you're in the 1st violin > section. Music is still being made, problems are still getting > solved. > ___ > 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] What is Haskell unsuitable for?
Andrew Coppin wrote: > aditya siram wrote: > > No argument there - I'm even afraid to stick it on my resume. At least > > Clojure can be snuck into the JVM without people noticing - Haskell, > > unfortunately, is not that shy. > > > > Oh, I don't know... Few companies will want you to *use* Haskell, but > lots of people seemed to be impressed if you say you know how to use it. > (Those that know WTF is actually is, anyway...) "Pascal? Yeah, I used to program in that about 30 years ago". I actually got that response from someone. Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Using Hint with a socket server
Hi Tom, There is probably more than one way to do this. Did you try using the package hint-server? [1] It has a very simple interface: you start a "server" and obtain a handle; then you can run an interpreter action using the handle. Something like this: > runIn handle (interpret msg (as :: MyType)) This expression has type IO (Either InterpreterError MyType). You can also run an interpreter action in the background. Keep in mind that the ghc-api is not thread safe, though, so you should start only one server and put the handle in an MVar Hope that helps Daniel [1] http://hackage.haskell.org/package/hint-server On Jun 17, 2010, at 6:35 PM, Tom Jordan wrote: I'm trying to receive small segments of Haskell code over a socket, and be able to evaluate them in real time in GHCI. I've already downloaded Hint and have run the test code, and it's working great. I'm also using the socket server code from Ch.27 of "Real World Haskell" and that is working well also. directly below is the function from the socket server code that handles the incoming messages. Instead of doing this: "putStrLn msg"... I want to send whatever is captured in "msg" to the GHC interpreter that is used in the Hint code, something like this: "eval msg". I'm not sure how to combine both of these functionalities to get them to work with each other.. -- A simple handler that prints incoming packets plainHandler :: HandlerFunc plainHandler addr msg = putStrLn msg Below is the full code for the socket server, then below that is "SomeModule" used in the Hint example test below that. -- file: ch27/syslogserver.hs import Data.Bits import Network.Socket import Network.BSD import Data.List type HandlerFunc = SockAddr -> String -> IO () serveLog :: String -- ^ Port number or name; 514 is default -> HandlerFunc -- ^ Function to handle incoming messages -> IO () serveLog port handlerfunc = withSocketsDo $ do -- Look up the port. Either raises an exception or returns -- a nonempty list. addrinfos <- getAddrInfo (Just (defaultHints {addrFlags = [AI_PASSIVE]})) Nothing (Just port) let serveraddr = head addrinfos -- Create a socket sock <- socket (addrFamily serveraddr) Datagram defaultProtocol -- Bind it to the address we're listening to bindSocket sock (addrAddress serveraddr) -- Loop forever processing incoming data. Ctrl-C to abort. procMessages sock where procMessages sock = do -- Receive one UDP packet, maximum length 1024 bytes, -- and save its content into msg and its source -- IP and port into addr (msg, _, addr) <- recvFrom sock 1024 -- Handle it handlerfunc addr msg -- And process more messages procMessages sock -- A simple handler that prints incoming packets plainHandler :: HandlerFunc plainHandler addr msg = putStrLn msg -- main = serveLog "8008" plainHandler module SomeModule(g, h) where f = head g = f [f] h = f import Control.Monad import Language.Haskell.Interpreter main :: IO () main = do r <- runInterpreter testHint case r of Left err -> printInterpreterError err Right () -> putStrLn "that's all folks" -- observe that Interpreter () is an alias for InterpreterT IO () testHint :: Interpreter () testHint = do say "Load SomeModule.hs" loadModules ["SomeModule.hs"] -- say "Put the Prelude, Data.Map and *SomeModule in scope" say "Data.Map is qualified as M!" setTopLevelModules ["SomeModule"] setImportsQ [("Prelude", Nothing), ("Data.Map", Just "M")] -- say "Now we can query the type of an expression" let expr1 = "M.singleton (f, g, h, 42)" say $ "e.g. typeOf " ++ expr1 say =<< typeOf expr1 -- say $ "Observe that f, g and h are defined in SomeModule.hs, " ++ "but f is not exported. Let's check it..." exports <- getModuleExports "SomeModule" say (show exports) -- say "We can also evaluate an expression; the result will be a string" let expr2 = "length $ concat [[f,g],[h]]" say $ concat ["e.g. eval ", show expr1] a <- eval expr2 say (show a) -- say "Or we can interpret it as a proper, say, int value!" a_int <- interpret expr2 (as :: Int) say (show a_int) -- say "This works for any monomorphic type, even for function types" let expr3 = "\\(Just x) -> succ x" say $ "e.g. we interpret " ++ expr
[Haskell-cafe] Fun Facts: A lazy bill
I share this just for the sake of fun. In Costa Rica (Central America) a new series of bills are to be emitted and to celebrate bio-diversity some animal drawings are going to be used. Look at the new 10.000 colones bill: http://www.bccr.fi.cr/WebPages/PaginaInicio/NuevaFamilia/10.html Choose "reverso" in order to see the other side. -- Leonel Fonseca. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Troubles Building LLVM
Hello All, I'm trying to get up and running with the very interesting llvm package[1] but I'm running into problems during the linking stage. ke...@sugarglider-2:~/projects/third-party/llvm-hs-bindings/examples/> make clean all rm -f HelloJIT Fibonacci BrainF Vector Array DotProd Arith Align Struct Varargs *.o *.hi *.s *.bc Fib *.exe *.exe.manifest *~ ghc -Wall -optl -w --make -o HelloJIT.exe -main-is HelloJIT.main HelloJIT.hs [1 of 1] Compiling HelloJIT ( HelloJIT.hs, HelloJIT.o ) Linking HelloJIT.exe ... Undefined symbols: "_LLVMAddCondPropagationPass", referenced from: _ssCM_info in libHSllvm-0.7.1.1.a(Scalar.o) ld: symbol(s) not found collect2: ld returned 1 exit status make: *** [HelloJIT.exe] Error 1 It's probably something very simple that I'm doing wrong since this is my first Haskell build linking against foreign libs. Do you know what I might be doing wrong? Here are the versions: Mac OS X 10.5.8 GHC 6.10.1 (waiting out a leopard installer bug [2]) llvm-2.7 installed to default location llvm package version 0.7.1.1 Thanks! BTW, the combination of this package plus the awesome Haskell parsers seem to make for a great compiler construction kit. I'm looking forward to playing around w/ llvm [1] http://hackage.haskell.org/package/llvm [2] http://trac.haskell.org/haskell-platform/ticket/110 -- keithsheppard.name ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Mining Twitter data in Haskell and Clojure
On Jun 17, 2:36 pm, "Claus Reinke" wrote: > > I'll work with Simon to investigate the runtime, but would welcome any > > ideas on further speeding up cafe4. > > Just a wild guess, but those foldWithKeys make me nervous. > > The result is strict, the step function tries to be strict, but if > you look at the code for Data.IntMap.foldr, it doesn't really > give you a handle for propagating that strictness. Unless > the foldr definition is inlined into your code, the generic, > non-strictly accumulating version might be called. Have > you checked that this isn't the case? > > Also, shouldn't the two foldWithKeys on dm be merged? > And, while Maps are strict in their representation, putting > them into a non-strict field of a data structure might lose > that. Claus -- thank you for the suggestions! Alas, it appears there's no strict foldWithKey in either Map or IntMap. Hence I had to cook one up with foldl' and fromList. I also merged both dm folds into one. The resulting tag is cafe5. It still gets killed by memory constraint at day 28. We're making progress here! :) -- Alexy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaskellWiki and Wikipedia
On Thu, Jun 17, 2010 at 6:36 AM, Roman Beslik wrote: > I mean that a link [[X]] leads to HaskellWiki if X exists in HaskellWiki > and to Wikipedia otherwise. Interwiki links requires to change all > occurrences of [[X]] when X is created. > [[wikipedia:{{PAGENAME}}]] may be handy on existing pages, it provides a > link to additional material. > I think this is probably a bad idea. Imagine trying to create a new page on the haskellwiki when wikipedia already has an article by the same name. Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
On Fri, Jun 18, 2010 at 5:03 AM, Erik de Castro Lopo > wrote: > Andrew Coppin wrote: > > > aditya siram wrote: > > > No argument there - I'm even afraid to stick it on my resume. At least > > > Clojure can be snuck into the JVM without people noticing - Haskell, > > > unfortunately, is not that shy. > > > > > > > Oh, I don't know... Few companies will want you to *use* Haskell, but > > lots of people seemed to be impressed if you say you know how to use it. > > (Those that know WTF is actually is, anyway...) > > "Pascal? Yeah, I used to program in that about 30 years ago". > > I actually got that response from someone. > > You only got it once? *Every single person* I say Haskell to hears Pascal. Maybe I have a speech impediment or somethings. While we're on the topic, does anyone else get funny looks when they say "monads"? Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Fun Facts: A lazy bill
Hello Leonel, Friday, June 18, 2010, 6:46:31 AM, you wrote: > to be used. Look at the new 10.000 colones bill: and this one - http://www.bccr.fi.cr/WebPages/PaginaInicio/NuevaFamilia/5.html is for C++ programmers :) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
Hello Martin, Thursday, June 17, 2010, 11:02:31 PM, you wrote: > But what if I want to apply a list of functions to a single argument. I can one more answer is "swing map": http://www.haskell.org/haskellwiki/Pointfree#Swing -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe