Re: [Haskell-cafe] Comments on Haskell 2010 Report
Hi wren, x**0 := 1, by convention. [...] So far as I'm aware, the x**0=1 vs 0**y=0 conflict leads to 0**0 [being] undefined x**0 is 1 /by definition, 0**y naturally is 0, since (for example) 0**2 expands to 0*0 (being 0 of course). So there is not a conflict of two definitions, it's simply a definition somehow /overriding/ the natural attempt. I guess I'm actually messing things up using the word natural - how can expand the multiplication of zero with itself zero times be natural? [...] more helpful in mathematics. /source-please Try it yourself: * Prove the binomial theorem *without* the convention 0**0 := 1 * Consider the function f(x) := x**0 - is it continuous (over the set of natural numbers including zero)? Donald E. Knut writes on the issue [1] (see page 6 of the generated output), defending the position x**0 being 1. Further: C99, Java define it that way. GHC does it that way. Standard Prelude of Haskell 98 Report defines ^ (** for natural numbers) as x ^ 0 = 1 [sic] The convention is also used in 6.4.3: The value of x^0 or x^^0 is 1 for any x, including zero [2] I know it's about ^ in that section, but why should x^0 be 1 and x**0 be undefined? (or: is the natural zero not the real zero?) greetings, Julian [1] http://www-cs-faculty.stanford.edu/~knuth/papers/tnn.tex.gz [2] http://www.haskell.org/onlinereport/basic.html#sect6.4.3 smime.p7s Description: S/MIME cryptographic signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Comments on Haskell 2010 Report
Hi, 8. [...] Saying 0**0 is undefined seems reasonable, but why 0**y? I agree on 0**y being 0 (not undefined), but why should 0**0 be undefined? x**0 := 1, by convention. Of course this is a still ongoing debate (regarding analysis of functions etc.), but the most usefull approach for /any/ programming language (and BTW for many mathematical proofs, too). -Julian smime.p7s Description: S/MIME cryptographic signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] MultiParamTypeClasses, FunctionalDependencies and FlexibleInstances using GHCi
Hello, i'm playin' around with GHCs Haskell and some extensions. I'm already aware of that functional dependencies are very very tricky, but there is something I don't understand about there implementation in GHC. I've constructed my own TypeClass Num providing a signature for (+), having multiple params a, b and c. I'm than declaring a (flexible) Instance for Prelude.Num, simply using (Prelude.+) for the definition of my (+) - and it does not work as I expect it to. First, this is the code: {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, TypeSynonymInstances, FlexibleInstances #-} import qualified Prelude class Num a b c | a b - c where (+) :: a - b - c instance (Prelude.Num x) = Num x x x where (+) = (Prelude.+) now if I load it into GHCi and type 3 + 4 i get a whole bunch of error-messages. I do understand that (3::Prelude.Int) + (4::Prelude.Int) works, since I've explicitly declared 3 and 4 to be Prelude.Int and there is a functional dependency stating that (+) :: a b determines the results type c, by the Instance declaration cleary c will be the same as a and b. Now, if I type 3 + 4 it does not work, and i really don't understand why. If i ask GHCi for 3's type ($ :t 3) it will answer 3 :: (Prelude.Num t) = t. But, if 3 and 4 are Prelude.Nums and there is an instanfe Num x x x for x of Prelude.Num - than why can't GHC deduce from the definitions that 3 and 4, both Prelude.Nums, can be used with (+) since there is an instance for Prelude.Num and my class Num - and the result will of course be something of Prelude.Num? best regards, Julian smime.p7s Description: S/MIME cryptographic signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe