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
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 :)
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
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
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
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.
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
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
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,
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.
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
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
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:
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
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
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
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
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) .
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
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
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)
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
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
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
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
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
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
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
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
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
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
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:
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
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
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
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
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
37 matches
Mail list logo