
Konrad Hinsen
On Thursday 21 August 2003 22:42, Jon Cast wrote:
(or any other type I declare it to be).
Right. But: you can declare it to have type Fractional alpha => alpha, which is the same type the constant has in the middle of an expression.
I can make such a declaration, but it still gets converted to Double.
How are you doing this? I'm not seeing the behavior you describe.
What I can do is turn my constant table into a function:
constant :: Fractional a =3D> String -> a constant "k_B" = 0.0083144708636327096
and have the return values be of type Fractional a =3D> a. But I suppose there is some runtime cost associated with such a function call, so I would rather avoid it.
Jon Cast

On Thursday 21 August 2003 23:23, Jon Cast wrote:
I can make such a declaration, but it still gets converted to Double.
How are you doing this? I'm not seeing the behavior you describe.
module Foo where x = 0.5 :: Fractional a => a Then I run "hugs Foo.hs" and get: Foo> :type x x :: Double Same with ghci. An even better illustration of my original problem is: module Foo where x = 0.5 :: Fractional a => a foo :: Fractional a => a -> a foo a = x*a This yields the error message ERROR "/home/hinsen/haskell/Foo.hs":6 - Inferred type is not general enough *** Expression : foo *** Expected type : Fractional a => a -> a *** Inferred type : Fractional Double => Double -> Double Konrad.

Konrad Hinsen writes: | On Thursday 21 August 2003 23:23, Jon Cast wrote: | > > I can make such a declaration, but it still gets converted to Double. | > | > How are you doing this? I'm not seeing the behavior you describe. | | module Foo where | x = 0.5 :: Fractional a => a Try x :: Fractional a => a x = 0.5 instead. That way, the type signature is in the right place to prevent defaulting. The other way is equivalent to x = (0.5 :: Fractional a => a) which only confirms a type which is inferred anyway Prelude> :type 0.5 0.5 :: Fractional a => a but does not count as a type signature for x. - Tom
participants (3)
-
Jon Cast
-
Konrad Hinsen
-
Tom Pledger