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
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
@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
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!
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
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
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!
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
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
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
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
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
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,
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
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
-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
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
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
_
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]
..
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
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
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
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
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'
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
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
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
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
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
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
30 matches
Mail list logo