ANNOUNCE: GHC 6.8.3 Release Candidate
Lennart Augustsson
lennart at augustsson.net
Sun Jun 1 14:50:22 EDT 2008
There are no rules written down. But the fast exponentiation
algorithm used by (^) assumes that (*) is associative.
I also don't think that fast exponentiation should ever multiply by 1.
-- Lennart
On Sun, Jun 1, 2008 at 6:34 PM, Serge D. Mechveliani <mechvel at botik.ru> wrote:
> On Sun, Jun 01, 2008 at 03:34:00PM +0100, Ian Lynagh wrote:
>> On Sun, Jun 01, 2008 at 05:39:49PM +0400, Serge D. Mechveliani wrote:
>> >
>> > This is why res and 1*res are not equivalent in Haskell-98 for
>> > res :: Num a => a.
>> >
>> > Am I missing something?
>>
>> The library functions assume that class instances obey some unwritten
>> laws; it's all a bit vague, but if your instances don't obey them then
>> you might find that things go wrong when using library functions. For
>> example, if your (*) isn't associative then (^) is going to give odd
>> results, and if the type of the second argument to (^) doesn't do
>> arithmetic in the normal way then very strange things could happen.
>>
>> Anyway, I've just tweaked the (^) definition again, so your code should
>> work in 6.8.3.
>
>
> Thank you.
> This helps -- in that the public DoCon-2.11 test will run (I hope).
>
> But I think that you have found a bug in the DoCon test program.
> Thank you.
> More precisely, here are my indeas.
>
>
> 1. Generally, for t = Num a => a, the expessions res :: t and
> ((fromInteger 1) :: t) * res
> are not equivalent in Haskell-98,
> and the compiler has not rigth to replace the former with the latter.
> Right?
>
> 2. But I guess, our current questions are different:
>
> (2.1) For t = Num a => a, has a Haskell implementation for (f^n) :: t
> right to base on certain natural properties of the operation
> fromInteger :: Integer -> t ?
> (2.2) Has a reliable mathematical application right to base on that
> for n > 0 the expression (f^n) :: Polynomial Integer
> does not imply computing fromInteger 1 :: Polynomial Integer
> ?
>
> Concerning (2.1): I do not know whether Haskell-98 allows to rely on
> that f^3 is equivalent to (fromInteger 1)*(f^3).
>
> But concerning (2.2), I think that (independently of the question (2.1))
> a reliable mathematical application must not presume the above properties
> of (^) and fromInteger.
>
> Concerning f^3 :: UPol Integer in my test for DoCon:
>
> 1) fromInteger _ :: UPol _ is defined as
> error "... use fromi instead".
> 2) (*) is defined via polMul ...
> 3) The expression f ^ 3 relies on the Haskell-98 library for (^).
> The Haskell library defines (^) via (*) -- all right.
>
> 4) DoCon has the function `power' to use instead of (^),
> and its library avoids (^).
> But for n > 0, I considered f^n :: UPol _
> as also correct. Because the Haskell library performs this via repeated
> application of (*).
> And I thought that if n > 0, then (fromInteger _ :: UPol _) will not
> appear.
> Maybe it does not appear in old GHC-s and does appear 6.8.3 ?
>
> I was using expressions like [(f ^ n) :: UPol Integer | n <- [2 .. 9]]
> in my _test programs_ for DoCon.
> But this relies on a particular property of the Haskell library definition
> for (f^n) :: a
> -- on that if n > 0 then (fromInteger _ :: a) does not appear in this
> computation.
>
> Now, I think, either I need to hide the standard (^) and overload it
> or to replace (^) with `power' in my examples too.
>
> Regards,
>
> -----------------
> Serge Mechveliani
> mechvel at botik.ru
>
>
>
>
>
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
More information about the Glasgow-haskell-users
mailing list