Re: [Haskell-cafe] Generating a random list

2008-03-01 Thread Milos Hasan
Hi, thanks for the reply.. Hi, so let's say I want to generate a list of N random floats. The elegant way of doing it would be to create an infinite lazy list of floats and take the first N, but for N = 1,000,000 or more, this overflows the stack. The reason is apparently that the take

Re: [Haskell-cafe] Generating a random list

2008-03-01 Thread Milos Hasan
Bryan O'Sullivan wrote: Milos Hasan wrote: so let's say I want to generate a list of N random floats. The elegant way of doing it would be to create an infinite lazy list of floats and take the first N, but for N = 1,000,000 or more, this overflows the stack. The reason is apparently that

Re: [Haskell-cafe] Generating a random list

2008-03-01 Thread Milos Hasan
So, I did one more experiment, and the following overflows too: import System.Random import Data.List randFloats :: [Float] randFloats = randoms (mkStdGen 0) main = print $ sum $ sort $ take 100 randFloats Could it be that Data.List.sort is the culprit that uses O(n) stack space here? If

Re: [Haskell-cafe] Generating a random list

2008-03-01 Thread Kalman Noel
Milos Hasan wrote: Here's a minimal summing example that illustrates the difference. The following works fine, since the elements are generated lazily and summed on the fly, as expected: randFloats :: [Float] randFloats = randoms (mkStdGen 0) main = do let xs = take 100

Re: [Haskell-cafe] Generating a random list

2008-03-01 Thread Luke Palmer
On Sat, Mar 1, 2008 at 8:18 AM, Milos Hasan [EMAIL PROTECTED] wrote: Here's a minimal summing example that illustrates the difference. The following works fine, since the elements are generated lazily and summed on the fly, as expected: randFloats :: [Float] randFloats = randoms

[Haskell-cafe] Re: Generating a random list

2008-03-01 Thread apfelmus
Milos Hasan wrote: import System.Random import Data.List randFloats :: [Float] randFloats = randoms (mkStdGen 0) main = print $ sum $ sort $ take 100 randFloats Could it be that Data.List.sort is the culprit that uses O(n) stack space here? If so, is this avoidable? sum is not

[Haskell-cafe] runInteractiveCommand dying uncatchably?

2008-03-01 Thread Evan Martin
If I run the following program, it never prints done. If I uncomment the commented line, it does. import Prelude hiding (catch) import Control.Exception import System.Process import System.IO demo = do putStrLn starting (inp,out,err,pid) - runInteractiveCommand nonesuchcommand putStrLn

Re: [Haskell-cafe] Generating a random list

2008-03-01 Thread Albert Y. C. Lai
The following is in ghci 6.8.2 with default options (e.g., default heap and stack). G denotes the ghci prompt. At some points ghci will use 500MB of memory. Be sure you have enough physical memory. G :m + Data.List System.Random G let f n = take n randoms (mkStdGen 0)) :: [Float] I define f

Re: [Haskell-cafe] Generating a random list

2008-03-01 Thread Milos Hasan
It is definitely the strictness analyzer biting you here. In ghci, the behavior of these two programs is identical (stack overflow). As kalman said, if you replate sum with foldl' (+) 0 in each of these programs, the behavior is still identical (correct). OK, I could replicate that

[Haskell-cafe] .cabal problem

2008-03-01 Thread Galchin Vasili
Hello, I am trying to install a package on my Linux Ubuntu machine. It chokes build-depends: base, directory because directory dependency is unresolvable. Do I have to specify extra-libs so that correct library space is searched? Actually I tried this and it didn't help. ?? Regards, Vasya

[Haskell-cafe] coerce (safe!)

2008-03-01 Thread Krzysztof Skrzętnicki
Well, it is simply coerce :: a - b coerce _ = undefined so coerce is simply empty function. But still, it is possible to write a function of type (a-b). Well, possibly I didn't write anything particularly new, but please excuse me for I'm still in sort of a shock after I've discovered it. Yet

Re: [Haskell-cafe] runInteractiveCommand dying uncatchably?

2008-03-01 Thread Brandon S. Allbery KF8NH
On Mar 1, 2008, at 13:39 , Evan Martin wrote: If I run the following program, it never prints done. If I uncomment the commented line, it does. The exception it's getting is a UNIX signal (SIGPIPE), whose default action if not caught is to silently kill the process. Establish a signal

Re: [Haskell-cafe] coerce (safe!)

2008-03-01 Thread Thomas Schilling
On 2 mar 2008, at 01.21, Krzysztof Skrzętnicki wrote: Well, it is simply coerce :: a - b coerce _ = undefined so coerce is simply empty function. But still, it is possible to write a function of type (a-b). Well, possibly I didn't write anything particularly new, but please excuse me

Re: [Haskell-cafe] .cabal problem

2008-03-01 Thread Adam Langley
2008/3/1 Galchin Vasili [EMAIL PROTECTED]: I am trying to install a package on my Linux Ubuntu machine. It chokes build-depends: base, directory because directory dependency is unresolvable. Do I have to specify extra-libs so that correct library space is searched? Actually I tried this

Re: [Haskell-cafe] Generating a random list

2008-03-01 Thread Chaddaï Fouché
2008/3/1, Milos Hasan [EMAIL PROTECTED]: OK, thanks, this is an important point. So maybe I should have done this? main = print $ foldl1' (+) $! take 100 randFloats My intuition tells me that the $! (and `seq`) just reduces one level (to WHNF?). If so, is there a way to force complete

[Haskell-cafe] Re: Generating a random list

2008-03-01 Thread Milos Hasan
OK, you convinced me that sort is not the problem. After all, last (f 100) overflows too, and last is a very innocent function. I don't know how you found the size (or structure) of the thunks (I'm not aware of a ghci functionality that can tell me that), could you let me know? Anyway,

Re: [Haskell-cafe] .cabal problem

2008-03-01 Thread Galchin Vasili
exactly .. I have version 6.6.1 ... question is how do I get the Unbuntu package for version 6.8? V. On Sat, Mar 1, 2008 at 8:02 PM, Adam Langley [EMAIL PROTECTED] wrote: 2008/3/1 Galchin Vasili [EMAIL PROTECTED]: I am trying to install a package on my Linux Ubuntu machine. It chokes

Re: [Haskell-cafe] Wrong kind when attempting to build a monad for a circular list of functions

2008-03-01 Thread Aaron Altman
A big thanks to you all for the discussion. I have determined that a monad is actually not the best representation of a circular list of functions. I was able to implement it without any special syntax or unusual typing. For the curious: --