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, th

Re: [Haskell-cafe] Error with Float

2005-07-19 Thread Josh Hoyt
On 7/19/05, Cale Gibbard <[EMAIL PROTECTED]> wrote: > 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. You > can define f as follows: > [snip] I agree on the stylistic front. Another approach is to make the gene

Re: [Haskell-cafe] Error with Float

2005-07-19 Thread Cale Gibbard
To get exact fractions, use the Ratio module (import Ratio) and the Rational type which is defined there. 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. You can define f as follows: f x = let t = 2 * x i

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

Re: [Haskell-cafe] Error with Float

2005-07-19 Thread Dinh Tien Tuan Anh
From: Cale Gibbard <[EMAIL PROTECTED]> Reply-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

Re: [Haskell-cafe] Error with Float

2005-07-19 Thread Cale Gibbard
Perhaps you mean: f x | x < 1 = 0 : f (2*x) | otherwise = 1 : f (2*(x-1)) Note that in the second case, the 1 is subtracted before multiplication by 2. If you were referring to the problem that this eventually gives constantly 0 for values like 0.6, try importing the Ratio module and

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 (0I guess there

[Haskell-cafe] Error with Float

2005-07-19 Thread Dinh Tien Tuan Anh
This is my function to convert a fraction (0I 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 wrong (will eventually evaluate an infinite 0, no matter what value of x) Please tell me there's s