tag:blogger.com,1999:blog-7094652.post8575289432112235262..comments2024-03-23T14:36:09.980+00:00Comments on Neil Mitchell's Blog (Haskell etc): Monomorphism and DefaultingNeil Mitchellhttp://www.blogger.com/profile/13084722756124486154noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-7094652.post-41996512552259104392012-04-12T11:22:42.904+01:002012-04-12T11:22:42.904+01:00I suppose that the two numbers actually match at a...I suppose that the two numbers actually match at an infinite number of places...(AFAIK it is believed that pi is a "normal number", and any normal number matches any rational number in 10% of its digits)Eryxhttps://www.blogger.com/profile/05661340944049650573noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-58730643312721874052009-03-04T15:24:00.000+00:002009-03-04T15:24:00.000+00:00> 13 matching digits, only 6 of which are conse...> 13 matching digits, only 6 of which are consecutive :-)<BR/><BR/>I actually laughed out loud at that one...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-20309826893003366762009-02-20T16:57:00.000+00:002009-02-20T16:57:00.000+00:00Once per type could also be done by need, memoing ...Once per type could also be done by need, memoing in fact.Tom Schrijvershttps://www.blogger.com/profile/05575578560152022579noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-84947762091455598832009-02-16T20:23:00.000+00:002009-02-16T20:23:00.000+00:00Morten: Ah, that's really interesting to know! I'l...Morten: Ah, that's really interesting to know! I'll have to figure out how to do that with the nice list processing style.Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-11954412786789295952009-02-16T13:15:00.000+00:002009-02-16T13:15:00.000+00:00If you stop the calculation of pie after 1e6, you ...If you stop the calculation of pie after 1e6, you will get an inaccuracy of that size due to the alternating nature of the series. <BR/>The average of pie_1000000 and pie_1000001 has a precision of around 5e-13, however.<BR/><BR/>Very interesting blog. I enjoy reading it. Cheers.Unknownhttps://www.blogger.com/profile/12719502371103599157noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-90538237369971450932009-02-15T10:39:00.000+00:002009-02-15T10:39:00.000+00:00redbeard: Yes,the transformation you suggest of on...redbeard: Yes,the transformation you suggest of once per type is possible in many cases (its called specialisation), but a Haskell program can have polymorphic recursion, which means there may _not_ be a finite number of types used in the program, and it can't work all cases.<BR/><BR/>Having defaulting happen only at use seems like a good idea - its certainly going in the right direction.<BR/><BR/>Anon: 13 matching digits, only 6 of which are consecutive :-) I would have said 12 dp of accuracy if I had it!Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-60796286442191794672009-02-04T15:28:00.000+00:002009-02-04T15:28:00.000+00:00A nit: "Thirteen matching digits should be su...A nit: "Thirteen matching digits should be suffient for most uses of pi" -- actually only 5 digits to the right of the decimal match:<BR/><BR/>> pi - pie<BR/>1.0000000187915248e-6Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-77267160039797706452009-02-04T14:09:00.000+00:002009-02-04T14:09:00.000+00:0023Skidoo: it gives a stack overflow because sum is...23Skidoo: it gives a stack overflow because sum is too lazy. Substitute "sum" with "foldl' (+) 0" and it should work.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-24762298955150280182009-02-04T11:35:00.000+00:002009-02-04T11:35:00.000+00:00Is the original pie function fine as it is? Am I r...Is the original pie function fine as it is? Am I right to think it's CAF already; as it has no class constraints? So we should accept the 4 seconds of evaluation?<BR/>PaulAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-58202292692761209262009-02-04T06:10:00.000+00:002009-02-04T06:10:00.000+00:00@martijn: Without hackery, no. However, there is s...@martijn: Without hackery, no. However, there is some hackery available if you're willing. The Template Haskell type class Language.Haskell.TH.Syntax.Lift defines a function lift which can be used thus:<BR/><BR/> foo = $(lift (CAF GOES HERE))<BR/><BR/>Of course you can use that splice anywhere, not just for CAFs.Unknownhttps://www.blogger.com/profile/05766067924472271354noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-38973963353064588922009-02-04T04:33:00.000+00:002009-02-04T04:33:00.000+00:00Hmm, GHC gives me a stack overflow for this functi...Hmm, GHC gives me a stack overflow for this function (even with -O2). Why doesn't it execute in constant space?Mikhail Glushenkovhttps://www.blogger.com/profile/16766775468165268210noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-59907551648340238222009-02-04T02:39:00.000+00:002009-02-04T02:39:00.000+00:00In cases where compile time evaluation isn't an op...In cases where compile time evaluation isn't an option couldn't the Standard just guarantee that pie will be evaluated at most once <I>per type</I>? That seems like the best of both worlds.<BR/><BR/>As for defaulting, I kind of feel that it should only happen when you use the function. For example, pie would be "(Enum a, Fractional a) => a", but if you used "print pie" it would use the default of Double for the instances of Show, Enum and Fractional. This way you could use pie as any type, but still get easy printing, etc.Mathias Stearnhttps://www.blogger.com/profile/17055783979411175605noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-39054131388085193972009-02-03T23:30:00.000+00:002009-02-03T23:30:00.000+00:00Of course this is not desirable if the value is in...Of course this is not desirable if the value is infinite... but for pie it would be fine and save 4 seconds at runtime.Martijnhttps://www.blogger.com/profile/03420202886083056827noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-63405587650818530912009-02-03T23:25:00.000+00:002009-02-03T23:25:00.000+00:00Is it possible to have a CAF be replaced by its co...Is it possible to have a CAF be replaced by its computed value at compile-time?Martijnhttps://www.blogger.com/profile/03420202886083056827noreply@blogger.com