Re: [Haskell-cafe] Re: Thread pool in GHC

2005-09-07 Thread Dinh Tien Tuan Anh
So is there a way to reuse thread ? I think eventhough threads in GHC are extremely lighweight, it still make a different if u keep launching and killing thread in so many times. TuanAnh Yes, but AFAIK, threads in Haskell are exceedingly lightweight, as they are only primitives for

Re: [Haskell-cafe] Re: Thread pool in GHC

2005-09-06 Thread Dinh Tien Tuan Anh
for an infinite times, so thread reuse would improve the performance by getting of the overhead of creating new thread. TuanAnh From: genneth [EMAIL PROTECTED] To: Dinh Tien Tuan Anh [EMAIL PROTECTED] CC: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Re: Thread pool in GHC Date: Tue, 6 Sep

RE: [Haskell-cafe] Re: Thread pool in GHC

2005-09-05 Thread Dinh Tien Tuan Anh
@haskell.org Subject: [Haskell-cafe] Re: Thread pool in GHC Date: Thu, 4 Aug 2005 16:47:56 + (UTC) Dinh Tien Tuan Anh tuananhbirm at hotmail.com writes: Can thread pool be implemented in GHC ? I have a program that is currently using about 12-15 threads (launch and kill for infinite

Re: [Haskell-cafe] List of functions

2005-08-31 Thread Dinh Tien Tuan Anh
Something like (untested)... xs - zipWith ($) forkIO (map (\f - f x y) funs) tids - sequence xs what does zipWith ($) do ? _ Be the first to hear what's new at MSN - sign up to our free newsletters!

[Haskell-cafe] List of functions

2005-08-30 Thread Dinh Tien Tuan Anh
Hi, Basically, i have several rules: f1 x y ... f2 x y ... . They are all of the same type, but different names because i'll later on launch one thread for each of them, i.e: forkIO (f1 x y) forkIO (f2 x y) . There maybe

[Haskell-cafe] Need a concurrency advice

2005-08-22 Thread Dinh Tien Tuan Anh
Hi, Basically, my program has 7 threads for 7 rules Rule1 Rule2 .. .. .. and they all use pattern-mattching (a rule MUST be evaluated by a thread) The problem is there are some overlapping rules, which match the same pattern and diifferent rules are likely to give different results (one

[Haskell-cafe] Internal error: scavenge_one

2005-08-08 Thread Dinh Tien Tuan Anh
i have the following error when running my program: interactive: internal error: scavenge_one: strange object 47 does anyone know what it is ? _ Be the first to hear what's new at MSN - sign up to our free newsletters!

Re: [Haskell-cafe] Thread pool in GHC

2005-08-04 Thread Dinh Tien Tuan Anh
And how to use that ? Did you try -threaded ? _ It's fast, it's easy and it's free. Get MSN Messenger 7.0 today! http://messenger.msn.co.uk ___ Haskell-Cafe mailing list

[Haskell-cafe] Thread pool in GHC

2005-08-03 Thread Dinh Tien Tuan Anh
Can thread pool be implemented in GHC ? I have a program that is currently using about 12-15 threads (launch and kill for infinite times) and when running, especially after Ctrl-C, my computer got freezed up. And if i ran it several times, the Stack overflows occurs. Cheers TuanAnh

Re: [Haskell-cafe] Using unsafePerformIO

2005-08-01 Thread Dinh Tien Tuan Anh
AFAICS it is safe provided.. f always returns the same value for a given argument list and.. f has no observable side effects. What are called side effects ? It looks to me like what you're trying to do is run three parallel evaluation algorithms and take the answer from whichever one

Re: [Haskell-cafe] Using unsafePerformIO

2005-08-01 Thread Dinh Tien Tuan Anh
So that's not safe, and thus it should be in the IO monad. How can i handle a lazy list with IO monad. For example, function co (x:xs) ¦c ==1 = 1:co (xs) ¦c == 2 = 0:co (xs) where c = unsafePerformIO(f (x:xs)) will be written without

[Haskell-cafe] Using unsafePerformIO

2005-07-29 Thread Dinh Tien Tuan Anh
Hi, i have the following f :: [a] - IO a f xs = do m - newMVar c1 - forkIO f1 xs m c2 - forkIO f2 xs m c3 - forkIO f3 xs m c- takeMVar m killThread c1 killThread c2 killThread c3 return c

Re: [Haskell-cafe] Error with Float

2005-07-20 Thread Dinh Tien Tuan Anh
To get exact fractions, use the Ratio module (import Ratio) and the Rational type which is defined there. Thanks dude, it works The code you wrote below has a serious style problem that I thought I'd point out: you shouldn't use the IO monad for pure functions. I've never known that,

[Haskell-cafe] Error with Float

2005-07-19 Thread Dinh Tien Tuan Anh
This is my function to convert a fraction (0x1) to binary : f x ¦t1= 0::f t ¦otherwise = 1::f (t-1) where t = 2*x I guess there's nothing wrong with that, but when traced, it has something like 0.6*2 - 1 = 0.61 This error got accumulated and made my f function

RE: [Haskell-cafe] Error with Float

2005-07-19 Thread Dinh Tien Tuan Anh
Opps, its 0:f t not 0:: f t and the same for 1:f (t-1) From: Dinh Tien Tuan Anh [EMAIL PROTECTED] To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Error with Float Date: Tue, 19 Jul 2005 14:48:55 + This is my function to convert a fraction (0x1) to binary : f x ¦t1

Re: [Haskell-cafe] Error with Float

2005-07-19 Thread Dinh Tien Tuan Anh
-To: Cale Gibbard [EMAIL PROTECTED] To: Dinh Tien Tuan Anh [EMAIL PROTECTED] CC: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Error with Float Date: Tue, 19 Jul 2005 11:00:34 -0400 Perhaps you mean: f x | x 1 = 0 : f (2*x) | otherwise = 1 : f (2*(x-1)) Note that in the second case

Re: [Haskell-cafe] Error with Float

2005-07-19 Thread Dinh Tien Tuan Anh
So there's no way to get exact stream that represents a fraction, such as: .5 = .1 .2 = .00110011001100110011 ??? From: Udo Stenzel [EMAIL PROTECTED] To: Dinh Tien Tuan Anh [EMAIL PROTECTED] Subject: Re: [Haskell-cafe] Error with Float Date: Tue, 19 Jul 2005

[Haskell-cafe] IO Monad

2005-07-18 Thread Dinh Tien Tuan Anh
Hi, Could anyone explain for me why its not possible to return a primitive type (such as Integer, String) while doing some IO actions ? e.g: foo :: IO() - String What does it have to do with lazy evalution paradigm ? Cheers _

[Haskell-cafe] Coin changing algorithm

2005-07-13 Thread Dinh Tien Tuan Anh
Hi, The problem is: Given an amount of money m, and unlimited coins of value 1p, 2p, 5p, 10p, 20p, 50p, £1 and £2 List ALL (distinct) ways of change for m, using no greater than k coins eg: m = 75, k = 5 = [50, 20, 5] [50, 20, 1,2,2] ..

Re: [Haskell-cafe] Coin changing algorithm

2005-07-13 Thread Dinh Tien Tuan Anh
Thanks for all your solutions It seems that recursion is the only way. i thought it is a variation of the integer parition problem so that can be solved linearly (by generating next solution in (anti)lexicographic order) i guess i have to learn Monads then, ^_^ Cheers From: Kurt [EMAIL

Re: [Haskell-cafe] Coin changing algorithm

2005-07-13 Thread Dinh Tien Tuan Anh
it's because of the impreative approach. Seem more elegent than a functional approach. Where is the best place to find out about Monads. The book by Richard Bird is pretty confusing. From: Radu Grigore [EMAIL PROTECTED] Reply-To: Radu Grigore [EMAIL PROTECTED] To: Dinh Tien Tuan Anh

Re: [Haskell-cafe] Can't explain this error

2005-07-12 Thread Dinh Tien Tuan Anh
i have just encountered another type error. This program tries to print out partitions of a positive integer (i guess) parts 0 = [[]] parts x = [concat (map (y:) parts(x-y) | y-[1..(x `div` 2)]] and got this error: Expression : map (y:) parts(x-y) Term

Re: [Haskell-cafe] Can't explain this error

2005-07-12 Thread Dinh Tien Tuan Anh
oh damn, thank you From: Jon Fairbairn [EMAIL PROTECTED] To: Dinh Tien Tuan Anh [EMAIL PROTECTED] CC: [EMAIL PROTECTED], haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Can't explain this error Date: Tue, 12 Jul 2005 14:08:00 +0100 On 2005-07-12 at 12:39- Dinh Tien Tuan Anh wrote

[Haskell-cafe] Interaction in Haskell

2005-07-11 Thread Dinh Tien Tuan Anh
Hi, im using Hugs 98 and learing how to use interactive Haskell. As read in the book: capitalise :: [Char] - [Char] capitalise = takeWhile(/='.') . map toUpper interact capitalise its said the program is FULLY INTERACTIVE, i.e: as soon as 'h' typed on the keyboard, an 'H'

Re: [Haskell-cafe] Interaction in Haskell

2005-07-11 Thread Dinh Tien Tuan Anh
You're right, i've been using shell in Emacs to run Hugs, but when back to normal terminal, it works. Just for curiousity, why does it happen ? Thank you very much Cheers Yes, it is certainly not Hugs which prevents from realtime interaction but it is the terminal you are using. If the

[Haskell-cafe] Can't explain this error

2005-07-11 Thread Dinh Tien Tuan Anh
could anyone tell me what i did wrong with this please sumHam :: Integer - Float sumHam n = sum [1/x | x-[1..n]] Error: type error in explicitly typed binding Term: sumHam Type: Integer - Integer Does not match : Integer - Float it only

Re: [Haskell-cafe] Can't explain this error

2005-07-11 Thread Dinh Tien Tuan Anh
Thanks for your reply, i just simply removed the first line and it works, but i dont understand why 1/x is not Float. Try this: sumHam :: Integer - Float sumHam n = sum [1.0/(fromIntegral x) | x-[-1..n]] -- Andy _ Use MSN

Re: [Haskell-cafe] Confused about Cyclic struture

2005-07-08 Thread Dinh Tien Tuan Anh
So is sharing already implemented in Haskell ? Do i have to use where clause to implement the sharing ? Thanks a lot for your help Cheers To understand cyclic structures it is useful to think of graph reduction, because these graphs allow us to conveniently represent sharing between

Re: [Haskell-cafe] Confused about Cyclic struture

2005-07-08 Thread Dinh Tien Tuan Anh
Another question, it's said in the book that using cyclic structure (like ones = 1:ones) , the list would be represented by a fixed amount of memory. Does it mean [1,1,1..] only occupy one cell of memory ? How about in take 100 [1,1,...] ? From: Dinh Tien Tuan Anh [EMAIL

[Haskell-cafe] Confused about Cyclic struture

2005-07-07 Thread Dinh Tien Tuan Anh
Hi, Im a newbie to Haskell and the concept of cyclic strutures has confused me a lot For example (taken from Richard Bird's book): ones = 1:ones Its clear that it involves a cyclic structure But: ones = repeat 1 repeat x = x:repeat x I dont really understand what the