Re: [Haskell-cafe] Style and a problem

2010-09-10 Thread Wanas
I should've mentioned that the maximum number in such a list is n. That's why it stuck me as 'a bit' inexpensive. \/\/ On Fri, Sep 10, 2010 at 5:02 AM, Richard O'Keefe o...@cs.otago.ac.nz wrote: On Sep 10, 2010, at 8:55 AM, Wanas wrote: Hey all, So I have a two part question (I'm new

Re: [Haskell-cafe] Style and a problem

2010-09-10 Thread Wanas
On Fri, Sep 10, 2010 at 1:06 AM, Nils Schweinsberg m...@n-sch.de wrote: Something like this? import Data.List newList :: Int - [[Int]] newList n = myNub [ l | l - undefined -- not really sure how you want -- to generate these lists :)

Re: [Haskell-cafe] Style and a problem

2010-09-10 Thread Brent Yorgey
On Fri, Sep 10, 2010 at 12:24:39PM +0300, Wanas wrote: On Fri, Sep 10, 2010 at 1:06 AM, Nils Schweinsberg m...@n-sch.de wrote: Something like this? import Data.List newList :: Int - [[Int]] newList n = myNub [ l | l - undefined -- not really sure how you want

Re: [Haskell-cafe] Style and a problem

2010-09-09 Thread Nils Schweinsberg
Am 09.09.2010 22:55, schrieb Wanas: Hey all, So I have a two part question (I'm new to haskell, so you can throw all your mugs at me). a) I want to write a function that generates lists of lists of size $n$. All having the property that sum lst = sum [1..n]. a-1) After that, I want to remove

Re: [Haskell-cafe] Style and a problem

2010-09-09 Thread Daniel Fischer
On Thursday 09 September 2010 22:55:14, Wanas wrote: Hey all, So I have a two part question (I'm new to haskell, so you can throw all your mugs at me). a) I want to write a function that generates lists of lists of size $n$. All having the property that sum lst = sum [1..n]. a-1) After

Re: [Haskell-cafe] Style and a problem

2010-09-09 Thread Bulat Ziganshin
Hello Wanas, Friday, September 10, 2010, 12:55:14 AM, you wrote: a) I want to write a function that generates lists of lists of size $n$. All having the property that sum lst = sum [1..n]. a-1) After that, I want to remove all permutations. My idea of you have very interesting questions.

Re: [Haskell-cafe] Style and a problem

2010-09-09 Thread Wanas
Although it was phrased as one, it wasn't. If it were a homework question, wouldn't you think that I'd be trained to do it or have a TA to ask? But who said that you're accusing me of anything :) Thanks for your concern, Bulat. \/\/ On Fri, Sep 10, 2010 at 1:47 AM, Bulat Ziganshin

Re: [Haskell-cafe] Style and a problem

2010-09-09 Thread Richard O'Keefe
On Sep 10, 2010, at 8:55 AM, Wanas wrote: Hey all, So I have a two part question (I'm new to haskell, so you can throw all your mugs at me). a) I want to write a function that generates lists of lists of size $n$. All having the property that sum lst = sum [1..n]. a-1) After that, I

Re: [Haskell-cafe] Style Guide for Haskell Code

2009-03-14 Thread Martijn van Steenbergen
Henning Thielemann wrote: Of course, style is a matter of taste. So there are as many good styles as programmers and there won't be an official style guide, I'm afraid. While that is true, it's no valid reason to not have a style guide. Sun's style guide for Java has been very successful,

Re: [Haskell-cafe] Style Guide for Haskell Code

2009-03-14 Thread Henning Thielemann
On Sat, 14 Mar 2009, Martijn van Steenbergen wrote: Henning Thielemann wrote: Of course, style is a matter of taste. So there are as many good styles as programmers and there won't be an official style guide, I'm afraid. While that is true, it's no valid reason to not have a style guide.

Re: [Haskell-cafe] Style Guide for Haskell Code

2009-03-13 Thread Henning Thielemann
On Tue, 10 Mar 2009, Manlio Perillo wrote: After a quick search with Google, it seems that there is not yet an official document for Style Guide for Haskell Code. I was only able to found: http://www.cs.caltech.edu/courses/cs11/material/haskell/misc/haskell_style_guide.html

[Haskell-cafe] Style Guide for Haskell Code

2009-03-10 Thread Manlio Perillo
After a quick search with Google, it seems that there is not yet an official document for Style Guide for Haskell Code. I was only able to found: http://www.cs.caltech.edu/courses/cs11/material/haskell/misc/haskell_style_guide.html http://urchin.earth.li/~ian/style/haskell.html

Re: [Haskell-cafe] Style Guide for Haskell Code

2009-03-10 Thread Johan Tibell
On Tue, Mar 10, 2009 at 4:34 PM, Manlio Perillo manlio_peri...@libero.it wrote: After a quick search with Google, it seems that there is not yet an official document for Style Guide for Haskell Code. I was only able to found:

Re: [Haskell-cafe] Style

2007-08-26 Thread Yitzchak Gale
Bjorn Bringert wrote: Here's a much more inefficient version, but it has the merit of being very easy to understand: tm_silly n = length $ takeWhile (=='0') $ reverse $ show $ product [1..n] Be careful with types - use Data.List.genericLength here instead of length. Otherwise, tm_silly n is

Re: [Haskell-cafe] Style

2007-08-26 Thread Chaddaï Fouché
2007/8/26, Yitzchak Gale [EMAIL PROTECTED]: Bjorn Bringert wrote: Here's a much more inefficient version, but it has the merit of being very easy to understand: tm_silly n = length $ takeWhile (=='0') $ reverse $ show $ product [1..n] Be careful with types - use Data.List.genericLength

Re: [Haskell-cafe] Style

2007-08-26 Thread Yitzchak Gale
I wrote: Be careful with types - use Data.List.genericLength here instead of length. Otherwise, tm_silly n is wrong for n = 13 (on my 32-bit machine) due to round-off error in the Int type. Are you sure you really tested tm_silly ? length is perfectly enough to count the 0 in n! since the

Re: [Haskell-cafe] Style

2007-08-26 Thread Chaddaï Fouché
2007/8/26, Yitzchak Gale [EMAIL PROTECTED]: True, that is not the problem. Using length forces the result to be Int, which is different than all of the other tm's so far. So for example, try this: [n | n - [0..25], tm_silly n /= tm n] You mean to say that tm_silly returns Int, which

[Haskell-cafe] Style

2007-08-24 Thread Arie Groeneveld
Hi, I defined several functions for calculating the number of trailing zero's of n! tm = sum . takeWhile(0) . iterate f . f where f = flip div 5 tm1 n = sum . takeWhile(0) . map (div n . (5^)) $ [1..] tm2 n = sum . takeWhile(0) . map (div n) $ iterate ((*)5) 5 tm3 = sum . takeWhile(0) .

Re: [Haskell-cafe] Style

2007-08-24 Thread Bjorn Bringert
On Aug 24, 2007, at 9:18 , Arie Groeneveld wrote: Hi, I defined several functions for calculating the number of trailing zero's of n! tm = sum . takeWhile(0) . iterate f . f where f = flip div 5 tm1 n = sum . takeWhile(0) . map (div n . (5^)) $ [1..] tm2 n = sum . takeWhile(0) . map

Re: [Haskell-cafe] Style

2007-08-24 Thread Arie Groeneveld
Bjorn Bringert wrote: Here's a much more inefficient version, but it has the merit of being very easy to understand: tm_silly n = length $ takeWhile (=='0') $ reverse $ show $ product [1..n] You're rigth. I came up with that one too the first time. But for large value's of n it

Re: [Haskell-cafe] Style

2007-08-24 Thread Henning Thielemann
On Fri, 24 Aug 2007, Arie Groeneveld wrote: I defined several functions for calculating the number of trailing zero's of n! tm = sum . takeWhile(0) . iterate f . f where f = flip div 5 This is very elegant! You could also inline 'f' tm4 = sum . takeWhile(0) . tail . iterate (flip div 5)

Re: [Haskell-cafe] Style

2007-08-24 Thread Mirko Rahn
tm = sum . takeWhile(0) . iterate f . f where f = flip div 5 Quite nice. I like tm5 0 = 0 tm5 n = let q = div n 5 in q + tm5 q This version corresponds to what I'm think when parsing |tm|, so I wrote it down directly. Also possible tm6 = sum . unfoldr ( \ n - case div n 5 of

Re: [Haskell-cafe] Style

2007-08-24 Thread Marc A. Ziegert
Marc A. Ziegert [EMAIL PROTECTED] tm_parallelizable_v1 = \n - sum . takeWhile (0) $ map (div n) fives where fives = iterate (*5) 1 tm_improved_v1 n = sum . takeWhile (0) $ iterate (div `flip` 5) (div n 5) tm_fastestIMHO n = let m=div n 5 in if m5 then m else m+tm_fastestIMHO m

Re: [Haskell-cafe] Style

2007-08-24 Thread Arie Groeneveld
Thanks for all the instructive replies and alternatives! Learned a bit more in terms of feeling about style and improvement of some of the functions: f.e. 'killing' the 'where' in my number one choice. Thanks @@i ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Style

2007-08-24 Thread Arie Groeneveld
Henning Thielemann wrote: tm4 = sum . takeWhile(0) . tail . iterate (flip div 5) FWIW: as a result of all this I learned to write this as: tm41 = sum . takeWhile(0) . tail . iterate (`div` 5) @@i ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Style

2007-08-24 Thread sievers
Arie Groeneveld wrote: tm = sum . takeWhile(0) . iterate f . f where f = flip div 5 Which one is the most elegant one generally speaking? I like that tm only uses div. My personal choice is 'tm'. I like 'tm3' (a revised version of tm2) in terms of pointlessness and not having a

Re: [Haskell-cafe] Style

2007-08-24 Thread Marc A. Ziegert
whops... i did check it, but that was a copypaste mistake. buggy: tm_parallelizable_v1 = \n - sum . takeWhile (0) $ map (div n) fives where fives = iterate (*5) 1 should be: tm_parallelizable_v1 = \n - sum . takeWhile (0) $ map (div n) fives where fives = iterate (*5) 5 - marc

Re[2]: [Haskell-cafe] style question: Writer monad or unsafeIOToST?

2006-08-25 Thread Bulat Ziganshin
Hello Gregory, Friday, August 25, 2006, 3:08:09 AM, you wrote: Some performance data: using unsafeIOToST to write log messages directly to the output, the simulation does 10^7 state updates in about 45 seconds on my 1.5 GHz ppc G4. Using LogT, with a list of strings as the monoid, it

Re: Re[2]: [Haskell-cafe] style question: Writer monad or unsafeIOToST?

2006-08-25 Thread Gregory Wright
Hi Bulat, On Aug 25, 2006, at 3:36 AM, Bulat Ziganshin wrote: Hello Gregory, Friday, August 25, 2006, 3:08:09 AM, you wrote: Some performance data: using unsafeIOToST to write log messages directly to the output, the simulation does 10^7 state updates in about 45 seconds on my 1.5 GHz ppc

[Haskell-cafe] style question: Writer monad or unsafeIOToST?

2006-08-24 Thread Gregory Wright
Hi, Thanks to the responses earlier from the list, the core of my simulator now happy processes tens of millions of state updates without running out of stack. The goal of the simulator is to produce a log of tag states, which can be analyzed to find statistics of how often the sensor tags

Re: [Haskell-cafe] style question: Writer monad or unsafeIOToST?

2006-08-24 Thread Chris Kuklewicz
Gregory Wright wrote: Hi, Thanks to the responses earlier from the list, the core of my simulator now happy processes tens of millions of state updates without running out of stack. The goal of the simulator is to produce a log of tag states, which can be analyzed to find statistics of how

Re: [Haskell-cafe] style question: Writer monad or unsafeIOToST?

2006-08-24 Thread Chris Kuklewicz
The problem with WriterT is it is too strict. See http://www.mail-archive.com/haskell@haskell.org/msg16088.html The fix is adding ~ to the patterns inside the definition of (=): ~(a,w) - runLogT m ~(b,w') - runLogT (k a) A lazy version of WriterT, called LogT:

Re: [Haskell-cafe] style question: Writer monad or unsafeIOToST?

2006-08-24 Thread Chris Kuklewicz
So using LogT instead of WriterT, and changing from Control.Monad.ST to Control.Monad.ST.Lazy I can make you code work as you wanted: {-# OPTIONS_GHC -fglasgow-exts #-} module Main where import Control.Monad.ST.Lazy import Data.STRef.Lazy import Maybe import Debug.Trace -- LogT, copied from

Re: [Haskell-cafe] style question: Writer monad or unsafeIOToST?

2006-08-24 Thread Bulat Ziganshin
Hello Gregory, Thursday, August 24, 2006, 7:29:47 PM, you wrote: it seems that unsafeIOToST is safe in this case, in the sense that why you are stuck to ST monad? isn't it better to use just IO monad? and about total style - again, you can use my lib or write this yourself so that all you

Re: [Haskell-cafe] style question: Writer monad or unsafeIOToST?

2006-08-24 Thread Gregory Wright
Hi Chris, Thank you. That is exactly what I needed to know. It's good to know that I'm not totally crazy and that with the lazier LogT the code can run as it was written. It seems as if a request should be made for a Writer.Lazy as well as the existing Writer.Strict. (The latter could well

Re: [Haskell-cafe] style question: Writer monad or unsafeIOToST?

2006-08-24 Thread Gregory Wright
Hi Bulat! On Aug 24, 2006, at 1:17 PM, Bulat Ziganshin wrote: Hello Gregory, Thursday, August 24, 2006, 7:29:47 PM, you wrote: it seems that unsafeIOToST is safe in this case, in the sense that why you are stuck to ST monad? isn't it better to use just IO monad? The IO monad may be

Re: [Haskell-cafe] style question: Writer monad or unsafeIOToST?

2006-08-24 Thread Chris Kuklewicz
class Ref m r | m-r where newRef readRef writeRef instance Ref IO IORef writeRef r x = writeIORef r $! x instance (Ref m r) = Ref (WriterT m) r where writeRef = lift . writeRef and so on... The code snippet above looks like a very good idea. The monad dependent operations