[Haskell-cafe] Re: about Haskell code written to be "too smart"

2009-03-24 Thread Heinrich Apfelmus
Manlio Perillo wrote: > Conal Elliott ha scritto: >> Manlio, >> >> We live in the age of participation -- of co-education. Don't worry >> about text-books. Contribute to some wiki pages & blogs today that >> share these smart techniques with others. >> > > When I started learning Haskell (by my

Re: [Haskell-cafe] Use unsafePerformIO to catch Exception?

2009-03-24 Thread Jonathan Cast
On Tue, 2009-03-24 at 23:13 -0700, Donn Cave wrote: > Quoth Duncan Coutts : > > > You must not do this. It breaks the semantics of the language. > > > > Other people have given practical reasons why you should not but a > > theoretical reason is that you've defined a non-continuous function. > > T

Re: [Haskell-cafe] Use unsafePerformIO to catch Exception?

2009-03-24 Thread Jake McArthur
Donn Cave wrote: Could you elaborate a little, in what sense are we (?) relying on it? I actually can't find any responses that make a case against it on a really practical level - I mean, it seems to be taken for granted that it will work as intended, and we're down to whether we ought to have

Re: [Haskell-cafe] Use unsafePerformIO to catch Exception?

2009-03-24 Thread Donn Cave
Quoth Duncan Coutts : > You must not do this. It breaks the semantics of the language. > > Other people have given practical reasons why you should not but a > theoretical reason is that you've defined a non-continuous function. > That is impossible in the normal semantics of pure functional langu

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread wren ng thornton
Manlio Perillo wrote: But this may be really a question of personal taste or experience. What is more "natural"? 1) pattern matching 2) recursion or 1) function composition 2) high level functions Which is more "natural": * C-style for-loops (aka assembly while-loops), or * any modern languag

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Erik de Castro Lopo
Jake McArthur wrote: > Richard O'Keefe wrote: > > May I suggest that the most important thing missing from > > all these versions of the function is a comment? > > Most of the time I shouldn't *care* how the function works. > > (And that, for me, is one of the key benefits of Haskell.) > > Althou

Re: [Haskell-cafe] Use unsafePerformIO to catch Exception?

2009-03-24 Thread Duncan Coutts
On Mon, 2009-03-23 at 08:11 -0400, Xiao-Yong Jin wrote: > Hi, > > I just feel it is not comfortable to deal with exceptions > only within IO monad, so I defined > > > tryArith :: a -> Either ArithException a > > tryArith = unsafePerformIO . try . evaluate You must not do this. It breaks the sema

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Gwern Branwen
On Tue, Mar 24, 2009 at 2:42 PM, Manlio Perillo wrote: > Tim Newsham ha scritto: >>> >>> These friends are very interested in Haskell, but it seems that the main >>> reason why they don't start to seriously learning it, is that when they >>> start reading some code, they feel the "Perl syndrome".

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jake McArthur
Richard O'Keefe wrote: May I suggest that the most important thing missing from all these versions of the function is a comment? Most of the time I shouldn't *care* how the function works. (And that, for me, is one of the key benefits of Haskell.) Although in this case, a proper name and type s

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Richard O'Keefe
May I suggest that the most important thing missing from all these versions of the function is a comment? Most of the time I shouldn't *care* how the function works. (And that, for me, is one of the key benefits of Haskell.) ___ Haskell-Cafe mailing lis

[Haskell-cafe] Re: Grouping - Map / Reduce

2009-03-24 Thread GüŸnther Schmidt
Hi Ketil, Ketil Malde schrieb: "Gü?nther Schmidt" writes: let say I got an unordered lazy list of key/value pairs like [('a', 99), ('x', 42), ('a', 33) ... ] and I need to sum up all the values with the same keys. So far I wrote a naive implementation, using Data.Map, foldl and insertWith.

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread John Meacham
On Tue, Mar 24, 2009 at 10:29:55PM +0300, Miguel Mitrofanov wrote: > Maybe it's just me, but I think that > > takeList ns xs = evalState (mapM (State . splitAt) ns) xs > > or even > > takeList = evalState . map (State . splitAt) > > would be much clearer than both versions. I love it! It wouldn't

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Alberto G. Corona
Perhaps is much easier to create one line compositions of functions in haskell rather than in C because the type system helps a lot in the process. However, reusability of source code and maintainability has never been taken seriously by haskell programmers, simply because there are no industrial p

[Haskell-cafe] Re: Grouping - Map / Reduce

2009-03-24 Thread Gü?nther Schmidt
Dear Luke, I suspect Black Magic at work here. This seems to work and I so don't have a clue why. But thank you very much nevertheless, I strongly suspect that, once I figured out why this works, I will have learned a very, very important trick indeed. Had I read "purely functional data stru

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jonathan Cast
On Tue, 2009-03-24 at 16:43 -0700, Donn Cave wrote: > If he really intended to promote some dumb code as a better > alternative to some otherwise equivalent smart code, `Smart' is Manlio's term --- or, rather, his characterization of his friends' reaction upon seeing some inscrutable piece of (app

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Clive Brettingham-Moore
Code like that is why I love Haskell, while I haven't written a Haskell program in years it is still a joy to read (much more so than the pretty good zipWith version). In reference to later comments: if you don't know Monads, you don't know Haskell; that goes double for high order functions. So rea

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Donn Cave
> Manlio -- You may be missing the point of my suggestion, which is to help > people *find* code that suits them, rather than changing anyone's coding > style. Optimizing code for one segment of readers is pessimizing it for > another. Instead of dumbing down the smart code, I'd like to help your

Re: [Haskell-cafe] Grouping - Map / Reduce

2009-03-24 Thread Ketil Malde
"Gü?nther Schmidt" writes: > let say I got an unordered lazy list of key/value pairs like > > [('a', 99), ('x', 42), ('a', 33) ... ] > > and I need to sum up all the values with the same keys. > > So far I wrote a naive implementation, using Data.Map, foldl and insertWith. Data.Map.fromListWith

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Conal Elliott ha scritto: And advices to experienced Haskell programmers about how to document their code so that it may help less experienced programmers. Manlio -- You may be missing the point of my suggestion, Ah, sorry. which is to help people *find* code that suits them, rathe

Re: [Haskell-cafe] Re: Exception handling in numeric computations

2009-03-24 Thread Henning Thielemann
On Tue, 24 Mar 2009, Xiao-Yong Jin wrote: Thanks for all the replies. Now I understand more about Exceptions and Errors. I guess all I need is to compose a larger monad, after all. I need to learn how to make two different stacks of monad transformers cooperate seamlessly, though. Until no

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Conal Elliott ha scritto: Manlio, We live in the age of participation -- of co-education. Don't worry about text-books. Contribute to some wiki pages & blogs today that share these smart techniques with others. When I started learning Haskell (by my initiative), what I did was: 1) Quick

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Benja Fallenstein
2009/3/24 Peter Verswyvelen : >> This strategy is doomed to failure, unfortunately. > > So it is the good strategy, because Haskell's slogan is "avoid success at > all cost" :-) IN THE YEAR 1987, WAR WAS BEGINNING BIG, IMPERATIVE SOFTWARE BEHEMOTHS CLASHED IN A STATE OF IMPURITY UNDER THE SHADO

Re: [Haskell-cafe] Re: Exception handling in numeric computations

2009-03-24 Thread Xiao-Yong Jin
Jake McArthur writes: > Xiao-Yong Jin wrote: > | Then, why is 'div' not of type 'a -> a -> ArithExceptionMonad a' ? > | Why does it throws this /ugly/ /error/ when it is applied to > | 0? Why is it not using some beautiful > | 'ArithExceptinoMonad'? Is 'Control.Exception' just pure > | /ugly/ a

Re: [Haskell-cafe] ghci + hopengl

2009-03-24 Thread Peter Verswyvelen
On Tue, Mar 24, 2009 at 11:35 PM, Scott A. Waterman wrote: > Duane - > > yes, please. I've been wondering how to compile to a Mac .app structure. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/mkbndl > Also, anyone have any hints about distributing Haskell apps for mac, when > you

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Conal Elliott
> > This question makes me wonder... why is explicit recursion taught first? > [...] > Perhaps also because teachers, being older than their students, are often mired in outdated thinking. On Tue, Mar 24, 2009 at 3:35 PM, Jake McArthur wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 >

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Conal Elliott
Manlio, We live in the age of participation -- of co-education. Don't worry about text-books. Contribute to some wiki pages & blogs today that share these smart techniques with others. Learning/progress is mainly results when people respond to their own incomprehension by moving into new & chal

Re: [Haskell-cafe] ghci + hopengl

2009-03-24 Thread Scott A. Waterman
Duane - yes, please. I've been wondering how to compile to a Mac .app structure. Also, anyone have any hints about distributing Haskell apps for mac, when you know the target will certianly *not* have a GHC environment on it? Thanks --ts On Mar 21, 2009, at 2:18 PM, Duane Johnson wrote:

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jake McArthur
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jonathan Cast wrote: | You know, this might actually need to be looked into. | | You need to know recursion and pattern-matching to *write* re-usable | higher-order functions, but how appropriate is that as the first thing | taught? An excellent ques

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Conal Elliott
> > And advices to experienced Haskell programmers about how to document their > code so that it may help less experienced programmers. > Manlio -- You may be missing the point of my suggestion, which is to help people *find* code that suits them, rather than changing anyone's coding style. Optim

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread Thomas Davie
*Launches missiles* Bob (that was my logo) On 24 Mar 2009, at 21:46, Ross Mellgren wrote: Doesn't matter how many times you seq the results, the thunk has been forced. -Ross On Mar 24, 2009, at 4:45 PM, FFT wrote: I demand a recount! The one that launches the missile should have won!

Re: [Haskell-cafe] Re: Exception handling in numeric computations

2009-03-24 Thread Jake McArthur
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Xiao-Yong Jin wrote: | Then, why is 'div' not of type 'a -> a -> ArithExceptionMonad a' ? | Why does it throws this /ugly/ /error/ when it is applied to | 0? Why is it not using some beautiful | 'ArithExceptinoMonad'? Is 'Control.Exception' just pur

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jonathan Cast
On Tue, 2009-03-24 at 23:15 +0100, Manlio Perillo wrote: > Dan Piponi ha scritto: > >> Miguel Mitrofanov wrote: > >>> takeList = evalState . mapM (State . splitAt) > > > >> However, ironically, I stopped using them for pretty > >> much the same reason that Manlio is saying. > > > > Are you saying

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jake McArthur
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Manlio Perillo wrote: | But this may be really a question of personal taste or experience. | What is more "natural"? | | 1) pattern matching | 2) recursion | or | 1) function composition | 2) high level functions Definitely the latter two. They are e

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Dan Piponi ha scritto: Miguel Mitrofanov wrote: takeList = evalState . mapM (State . splitAt) However, ironically, I stopped using them for pretty much the same reason that Manlio is saying. Are you saying there's a problem with this implementation? It's the only one I could just read immed

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread John Melesky
On Mar 24, 2009, at 1:51 PM, Manlio Perillo wrote: But this may be really a question of personal taste or experience. What is more "natural"? 1) pattern matching 2) recursion or 1) function composition 2) high level functions I think, actually, that one of the fundamental intuitions of (modern

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Peter Verswyvelen
On Tue, Mar 24, 2009 at 8:29 PM, Miguel Mitrofanov wrote: > takeList ns xs = evalState (mapM (State . splitAt) ns) xs >> > > or even > > takeList = evalState . map (State . splitAt) > > would be much clearer than both versions. Brilliant. As a newbie, I knew all these functions, I have used them

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Conal Elliott ha scritto: I'd love to help newbies get the hang of Haskell without having to jump in the deep (and smart-infested) end first. And I'd love for people to keep writing smart code for non-newbies to enjoy. Perhaps a practical suggestion would be some wiki pages devoted to pointi

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread Jeff Wheeler
Yay, thanks everybody! As Eelco pointed out, Darrin Thompson deserves much of the credit for coming up with the design; I just made it pretty in Photoshop. :) On Tue, 2009-03-24 at 08:29 -0400, John Van Enk wrote: > Is this the part where all the pundits come out and talk about how > Jeff isn't

Re: [Haskell-cafe] Grouping - Map / Reduce

2009-03-24 Thread Luke Palmer
On Tue, Mar 24, 2009 at 3:51 PM, Luke Palmer wrote: > On Tue, Mar 24, 2009 at 3:15 PM, Gü?nther Schmidt wrote: > >> Hi, >> >> let say I got an unordered lazy list of key/value pairs like >> >> [('a', 99), ('x', 42), ('a', 33) ... ] >> >> and I need to sum up all the values with the same keys. >>

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Erik de Castro Lopo ha scritto: Manlio Perillo wrote: I was speaking about the best way to write a function, so that it may help someone who is learning Haskell. I've been learning Haskell for about 3 months. I think its a mistake to write code so that its easy for someone learning Haskell t

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Zachary Turner ha scritto: [...] > but I do understand that one of the primary uses cases and/or motivating factors for using Haskell is when you really just NEED that extra abstraction and power you get from being able to do these types of things. Someone once said that "simple problems shou

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Loup Vaillant
2009/3/24 Manlio Perillo : > Jonathan Cast ha scritto: >> >> [...] >> >> I think, in general, the best way to document the purpose of the >> function is >> >>    -- | Split a function into a sequence of partitions of specified >> lenth >>    takeList :: [Int] -> [a] -> [[a]] *That* was what I crav

Re: [Haskell-cafe] Grouping - Map / Reduce

2009-03-24 Thread Luke Palmer
On Tue, Mar 24, 2009 at 3:15 PM, Gü?nther Schmidt wrote: > Hi, > > let say I got an unordered lazy list of key/value pairs like > > [('a', 99), ('x', 42), ('a', 33) ... ] > > and I need to sum up all the values with the same keys. > > So far I wrote a naive implementation, using Data.Map, foldl an

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jonathan Cast
On Tue, 2009-03-24 at 22:43 +0100, Manlio Perillo wrote: > Jonathan Cast ha scritto: > > [...] > > > > I think, in general, the best way to document the purpose of the > > function is > > > > -- | Split a function into a sequence of partitions of specified > > lenth > > takeList :: [Int]

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Conal Elliott
I'd love to help newbies get the hang of Haskell without having to jump in the deep (and smart-infested) end first. And I'd love for people to keep writing smart code for non-newbies to enjoy. Perhaps a practical suggestion would be some wiki pages devoted to pointing out code with various learni

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Ross Mellgren
As (yet another?) Haskell newbie, with a day job using Java (where "keep it simple, stupid" is not a principle, it's a language enforced requirement), I would much prefer the function is implemented in the most concise and idiomatic style that the writer is capable of. That is, either the z

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Erik de Castro Lopo
Manlio Perillo wrote: > I was speaking about the best way to write a function, so that it may > help someone who is learning Haskell. I've been learning Haskell for about 3 months. I think its a mistake to write code so that its easy for someone learning Haskell to read it. Code should be writt

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread Andres Loeh
>> The results of the Haskell logo competition are in! >> >> You can view them at >> http://www.cs.cornell.edu/w8/~andru/cgi-perl/civs/results.pl?num_winners=1&id=E_d21b0256a4fd5ed7&algorithm=beatpath >> >> Congratulations Jeff Wheeler! > > Is there also a measure of how strong the winner wins ove

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread Max Rabkin
On Tue, Mar 24, 2009 at 11:41 PM, Henning Thielemann wrote: >> http://www.cs.cornell.edu/w8/~andru/cgi-perl/civs/results.pl?num_winners=1&id=E_d21b0256a4fd5ed7&algorithm=beatpath >> > Is there also a measure of how strong the winner wins over the "losers"? The runner up was beaten 135 votes to 10

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread Henning Thielemann
On Tue, 24 Mar 2009, Eelco Lempsink wrote: The results of the Haskell logo competition are in! You can view them at http://www.cs.cornell.edu/w8/~andru/cgi-perl/civs/results.pl?num_winners=1&id=E_d21b0256a4fd5ed7&algorithm=beatpath Congratulations Jeff Wheeler! And ... please maintain the

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Jonathan Cast ha scritto: [...] I think, in general, the best way to document the purpose of the function is -- | Split a function into a sequence of partitions of specified lenth takeList :: [Int] -> [a] -> [[a]] Note that I was not speaking about the best way to document a function

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread Henning Thielemann
On Tue, 24 Mar 2009, Eelco Lempsink wrote: The results of the Haskell logo competition are in! You can view them at http://www.cs.cornell.edu/w8/~andru/cgi-perl/civs/results.pl?num_winners=1&id=E_d21b0256a4fd5ed7&algorithm=beatpath Congratulations Jeff Wheeler! Is there also a measure of

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Gregg Reynolds
On Tue, Mar 24, 2009 at 12:41 PM, Manlio Perillo wrote: > I too have this feeling, from time to time. > So do I, because I haven't had the time to learn what I need to learn in order to read the code smoothly. I find that when I do work out the meaning, most often the style reflects conciseness

Re: [Haskell-cafe] Re: Exception handling in numeric computations

2009-03-24 Thread Henning Thielemann
On Tue, 24 Mar 2009, Xiao-Yong Jin wrote: Jake McArthur writes: Xiao-Yong Jin wrote: | The problem is that there will be many functions using such | a function to invert a matrix, making this inversion | function return Either/Maybe or packing it in a monad is | just a big headache. I disag

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Yitzchak Gale
Miguel Mitrofanov wrote: >>> takeList = evalState . mapM (State . splitAt) I wrote: >> However, ironically, I stopped using them for pretty >> much the same reason that Manlio is saying. Dan Piponi wrote: > Are you saying there's a problem with this implementation? It's the > only one I could jus

Re: [Haskell-cafe] Are there performant mutable Arrays in Haskell?

2009-03-24 Thread Xiao-Yong Jin
"Brettschneider, Matthias" writes: > Thx for your hints, I played around with them and the performance gets > slightly better. > But the major boost is still missing :) > > I noticed, that one real bottleneck seems to be the conversion of the array > back into a list. > The interesting part

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jonathan Cast
On Tue, 2009-03-24 at 22:33 +0300, Eugene Kirpichov wrote: > Pretty cool once you know what the function does, but I must admit I > wouldn't immediately guess the purpose of the function when written in > this way. I wouldn't immediately guess the purpose of the function written in any way. I thi

[Haskell-cafe] Re: Exception handling in numeric computations

2009-03-24 Thread Xiao-Yong Jin
Daniel Yokomizo writes: > On Tue, Mar 24, 2009 at 1:27 PM, Xiao-Yong Jin wrote: >> Henning Thielemann writes: >> >>> Try to never use exception handling for catching programming errors! >>> Division by zero is undefined, thus a programming error when it >>> occurs. >>>  http://www.haskell.org/h

Re: [Haskell-cafe] Re: Exception handling in numeric computations

2009-03-24 Thread Luke Palmer
On Tue, Mar 24, 2009 at 3:28 PM, Luke Palmer wrote: > On Tue, Mar 24, 2009 at 3:14 PM, Xiao-Yong Jin wrote: > >> Jake McArthur writes: >> >> > Xiao-Yong Jin wrote: >> > | The problem is that there will be many functions using such >> > | a function to invert a matrix, making this inversion >> >

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Zachary Turner
On Tue, Mar 24, 2009 at 4:11 PM, Manlio Perillo wrote: > Conal Elliott ha scritto: > >> Another helpful strategy for the reader is to get smarter, i.e. to invest >> effort in rising to the level of the writer. Or just choose a different >> book if s/he prefers. - Conal >> >> > This strategy is

Re: [Haskell-cafe] Re: Exception handling in numeric computations

2009-03-24 Thread Luke Palmer
On Tue, Mar 24, 2009 at 3:14 PM, Xiao-Yong Jin wrote: > Jake McArthur writes: > > > Xiao-Yong Jin wrote: > > | The problem is that there will be many functions using such > > | a function to invert a matrix, making this inversion > > | function return Either/Maybe or packing it in a monad is > >

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Dan Piponi
> Miguel Mitrofanov wrote: >> takeList = evalState . mapM (State . splitAt) > However, ironically, I stopped using them for pretty > much the same reason that Manlio is saying. Are you saying there's a problem with this implementation? It's the only one I could just read immediately. The trick is

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Bas van Dijk
2009/3/24 Peter Verswyvelen : > But aren't these two definitions different algoritms? At first sight I think > the second one is more efficient than the first one. Some performance numbers: -- module Main where import System.En

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Gregg Reynolds
On Tue, Mar 24, 2009 at 1:42 PM, Manlio Perillo wrote: > > But, as an example, when you read a function like: > > buildPartitions xs ns = zipWith take ns . init $ scanl (flip drop) xs ns > > that can be rewritten (argument reversed) as: > > takeList :: [Int] -> [a] -> [[a]] > takeList [] _        

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Peter Verswyvelen
On Tue, Mar 24, 2009 at 10:11 PM, Manlio Perillo wrote: > This strategy is doomed to failure, unfortunately. So it is the good strategy, because Haskell's slogan is "avoid success at all cost" :-) > We live in the real world, compromises are necessary. I don't think so. It's just that we hav

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Conal Elliott
"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man." - George Bernard Shaw On Tue, Mar 24, 2009 at 2:11 PM, Manlio Perillo wrote: > Conal Elliott ha scritto: > >> Another h

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Conal Elliott
Hah! It sure is. :) On Tue, Mar 24, 2009 at 2:17 PM, Peter Verswyvelen wrote: > Sometimes that is very hard when the writer is way smarter than the reader > :-) > 2009/3/24 Conal Elliott > > Another helpful strategy for the reader is to get smarter, i.e. to invest >> effort in rising to the le

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Lutz Donnerhacke
* Manlio Perillo wrote: > But this may be really a question of personal taste or experience. > What is more "natural"? > > 1) pattern matching > 2) recursion > or > 1) function composition > 2) high level functions Composition of library functions is usually much more readable than hand written re

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Peter Verswyvelen
Sometimes that is very hard when the writer is way smarter than the reader :-) 2009/3/24 Conal Elliott > Another helpful strategy for the reader is to get smarter, i.e. to invest > effort in rising to the level of the writer. Or just choose a different > book if s/he prefers. - Conal > > > On

[Haskell-cafe] Grouping - Map / Reduce

2009-03-24 Thread Gü?nther Schmidt
Hi, let say I got an unordered lazy list of key/value pairs like [('a', 99), ('x', 42), ('a', 33) ... ] and I need to sum up all the values with the same keys. So far I wrote a naive implementation, using Data.Map, foldl and insertWith. The result of this grouping operation, which is effectiv

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread John Van Enk
If any one seconds the motion, i'm picking up this part of the thread and putting it in the humor section of the haskell wiki. /jve On Tue, Mar 24, 2009 at 4:48 PM, Ross Mellgren wrote: > import Diebold.Unsafe (unsafeChangeVotes)... > > ? > > -Ross > > On Mar 24, 2009, at 4:47 PM, John Van Enk

[Haskell-cafe] Re: Exception handling in numeric computations

2009-03-24 Thread Xiao-Yong Jin
Jake McArthur writes: > Xiao-Yong Jin wrote: > | The problem is that there will be many functions using such > | a function to invert a matrix, making this inversion > | function return Either/Maybe or packing it in a monad is > | just a big headache. > > I disagree. If you try to take the invers

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Conal Elliott ha scritto: Another helpful strategy for the reader is to get smarter, i.e. to invest effort in rising to the level of the writer. Or just choose a different book if s/he prefers. - Conal This strategy is doomed to failure, unfortunately. We live in the real world, compromis

Re: [Haskell-cafe] Making videos of your project

2009-03-24 Thread Don Stewart
claus.reinke: > Perhaps the "make a video" slogan doesn't quite explain what is > intended - it didn't to me!-) Reading John Udell's short article > > What is Screencasting? > http://www.oreillynet.com/pub/a/oreilly/digitalmedia/2005/11/16/what-is-screencasting.html?page=1 > > gave me a better idea

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Conal Elliott
"Recursion is the goto of functional programming". Also, "Do not confuse what is natural with what is habitual." - Conal On Tue, Mar 24, 2009 at 1:51 PM, Manlio Perillo wrote: > Jake McArthur ha scritto: > >> [...] >> | With my function, instead, you only have to "follow" 1 operation: >> | >> |

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Conal Elliott
Another helpful strategy for the reader is to get smarter, i.e. to invest effort in rising to the level of the writer. Or just choose a different book if s/he prefers. - Conal On Tue, Mar 24, 2009 at 1:44 PM, Manlio Perillo wrote: > Yitzchak Gale ha scritto: > >> [...] >> So the bottom line is

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Jake McArthur ha scritto: [...] | With my function, instead, you only have to "follow" 1 operation: | | Prelude> (head, tail) = splitAt n xs I think you are way oversimplifying your own code. ~takeList :: [Int] -> [a] -> [[a]] ~takeList [] _ = [] ~takeList _ [] = [

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread Ross Mellgren
import Diebold.Unsafe (unsafeChangeVotes) ... ? -Ross On Mar 24, 2009, at 4:47 PM, John Van Enk wrote: Unless there's a rogue unsafeChangeVotes call in there somewhere. On Tue, Mar 24, 2009 at 4:46 PM, Ross Mellgren hask...@z.odi.ac> wrote: Doesn't matter how many times you seq the results,

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread John Van Enk
Unless there's a rogue unsafeChangeVotes call in there somewhere. On Tue, Mar 24, 2009 at 4:46 PM, Ross Mellgren wrote: > Doesn't matter how many times you seq the results, the thunk has been > forced. > > -Ross > > > On Mar 24, 2009, at 4:45 PM, FFT wrote: > > I demand a recount! The one that l

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread Luke Palmer
On Tue, Mar 24, 2009 at 2:45 PM, FFT wrote: > I demand a recount! The one that launches the missile should have won! I guess nobody evaluated its merits. > > > 2009/3/24 Eelco Lempsink : > > The results of the Haskell logo competition are in! > > > > You can view them at > > > http://www.cs.c

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread Ross Mellgren
Doesn't matter how many times you seq the results, the thunk has been forced. -Ross On Mar 24, 2009, at 4:45 PM, FFT wrote: I demand a recount! The one that launches the missile should have won! 2009/3/24 Eelco Lempsink : The results of the Haskell logo competition are in! You can view th

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread FFT
I demand a recount! The one that launches the missile should have won! 2009/3/24 Eelco Lempsink : > The results of the Haskell logo competition are in! > > You can view them at > http://www.cs.cornell.edu/w8/~andru/cgi-perl/civs/results.pl?num_winners=1&id=E_d21b0256a4fd5ed7&algorithm=beatpath > >

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Yitzchak Gale ha scritto: [...] So the bottom line is that Manlio is right, really. It's just that Haskell is still very different than what most programmers are used to. So it does take a while to get a feeling for what is "too smart". Right, you centered the problem! The problem is where to

Re: Exception handling in numeric computations (was Re: [Haskell-cafe] Use unsafePerformIO to catch Exception?)

2009-03-24 Thread Henning Thielemann
On Tue, 24 Mar 2009, Daniel Yokomizo wrote: If we try the other approach, we need to express the totality of invMat by restricting its domain, so we can add, for example, a phantom type to Matrix to signal it is invertible. As you need to construct the Matrix before trying to invert it you can

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Peter Verswyvelen
On Tue, Mar 24, 2009 at 7:48 PM, Jonathan Cast wrote: > On Tue, 2009-03-24 at 19:42 +0100, Manlio Perillo wrote: > > But, as an example, when you read a function like: > > > > buildPartitions xs ns = zipWith take ns . init $ scanl (flip drop) xs ns > > > > that can be rewritten (argument reversed)

Re: Exception handling in numeric computations (was Re: [Haskell-cafe] Use unsafePerformIO to catch Exception?)

2009-03-24 Thread Henning Thielemann
On Tue, 24 Mar 2009, Xiao-Yong Jin wrote: invMat :: Matrix -> Matrix You won't be able to invert all the matrix, mathematically. And computationally, even a larger set of matrix might fail to be inverted because of the finite precision. It is relatively easier and more efficient to spot such

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jake McArthur
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Manlio Perillo wrote: | With the original version, you have to "follow" 3 separate operations: | | Prelude> let xs = [1, 2, 3, 4] :: [Int] | Prelude> let ns = [3, 1] :: [Int] | Prelude> let _1 = scanl (flip drop) xs ns | Prelude> let _2 = init _1 | Pr

Re: [Haskell-cafe] Re: Hugs on iPhone

2009-03-24 Thread David Leimbach
2009/3/24 Rick R > Correct. My point was only in the case that it would need to statically > link to a GPL'd lib (which I'm not sure if such a case exists) > If the gcc license suddenly decided to claim compiled items as derivative > works, the IT world as we know it would end. Any linkage to G

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Yitzchak Gale
Manlio Perillo complained about: >> buildPartitions xs ns = zipWith take ns . init . scanl (flip drop) xs $ ns Miguel Mitrofanov wrote: > takeList = evalState . mapM (State . splitAt) Ha! Bravo! As the author of the offending zipWith/scanl version, I can say that love those State monad one-liner

Re: [Haskell-cafe] The votes are in!

2009-03-24 Thread John Van Enk
> and that baby eating is an acceptable part of Haskell optimization Actually, yes. It's usually best used like this: data Foo = Bar {-# UNPACK #-} {-# EAT BABY #-} !Int On Tue, Mar 24, 2009 at 8:42 AM, Creighton Hogg wrote: > 2009/3/24 John Van Enk : > > Is this the part where all the pundits

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Jake McArthur ha scritto: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Manlio Perillo wrote: | This is right. | The problem is that often (IMHO) a function definition can be rewritten | so that it is much more readable. | | As an example, with the takeList function I posted. I looked at it, fo

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jake McArthur
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Miguel Mitrofanov wrote: | Maybe it's just me, but I think that | | takeList ns xs = evalState (mapM (State . splitAt) ns) xs | | or even | | takeList = evalState . map (State . splitAt) | | would be much clearer than both versions. Definitely. I stu

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Eugene Kirpichov
Pretty cool once you know what the function does, but I must admit I wouldn't immediately guess the purpose of the function when written in this way. 2009/3/24 Miguel Mitrofanov : >> | As an example, with the takeList function I posted. >> >> I looked at it, found nothing wrong with the original,

Re: [Haskell-cafe] ACM Task for C++ and Java programmers in Haskell. How to make code faster?

2009-03-24 Thread Vasyl Pasternak
I changed the program, now it similar to the program from the wiki (http://www.haskell.org/haskellwiki/Phone_number) The version with ByteString compared to version with ordinary Strings works 3.5 times faster. (I put it to http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2830) But version with Data

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Miguel Mitrofanov
| As an example, with the takeList function I posted. I looked at it, found nothing wrong with the original, and absolutely hated your "fixed" version. I might have written it like this, instead: ~buildPartitions xs ns = zipWith take ns . init . scanl (flip drop) xs $ ns Maybe it's j

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Eugene Kirpichov
2009/3/24 Manlio Perillo : > Tim Newsham ha scritto: >>> >>> These friends are very interested in Haskell, but it seems that the main >>> reason why they don't start to seriously learning it, is that when they >>> start reading some code, they feel the "Perl syndrome". >>> >>> That is, code written

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Tim Newsham
When you think about it, what you are saying is that Haskell programmers shouldn't take advantage of the extra tools that Haskell provides. No, I'm not saying this. But, as an example, when you read a function like: buildPartitions xs ns = zipWith take ns . init $ scanl (flip drop) xs ns tha

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jake McArthur
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Manlio Perillo wrote: | This is right. | The problem is that often (IMHO) a function definition can be rewritten | so that it is much more readable. | | As an example, with the takeList function I posted. I looked at it, found nothing wrong with the

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Jonathan Cast
On Tue, 2009-03-24 at 19:42 +0100, Manlio Perillo wrote: > Tim Newsham ha scritto: > >> These friends are very interested in Haskell, but it seems that the > >> main reason why they don't start to seriously learning it, is that > >> when they start reading some code, they feel the "Perl syndrome"

Re: [Haskell-cafe] about Haskell code written to be "too smart"

2009-03-24 Thread Manlio Perillo
Jake McArthur ha scritto: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Manlio Perillo wrote: | These friends are very interested in Haskell, but it seems that the main | reason why they don't start to seriously learning it, is that when they | start reading some code, they feel the "Perl syndro

  1   2   >