RE: specializing on existentially quantified data types

Thanks Lennart -- you are quite right. That comes of sending email before having my morning coffee. Yes you can make the specialised foo', but it'll never be called -- unless you call foo on a *particular* data structure and inlining removes the MkC wrapper etc. GHC is, of course, magical, but not quite that magical. You could do a run-time type test (via class Typeable, making Typeable a superclass of C), and then you *would* be able to call the specialised foo --- but at the cost of the test. Which is, I guess, not unreasonable. Simon | -----Original Message----- | From: Lennart Augustsson [mailto:lennart@augustsson.net] | Sent: 25 November 2003 09:08 | To: Simon Peyton-Jones | Cc: Hal Daume III; GHC Users Mailing List | Subject: Re: specializing on existentially quantified data types | | I don't know how specialised code works in ghc, so I have to ask. | Does this actually work? | The type of x is never known at the foo' call site, so the specialised | version of foo' will only be called if ghc does a run time test on the | type when invoking foo'. Does it do that? | | -- Lennart | | Simon Peyton-Jones wrote: | > | class C a where ... | > | data MkC = forall a . C a => MkC a | > | | > | foo :: MkC -> ... | > | | > | and I want to specialize foo for when the 'a' in the MkC is, say, Int. | > Is | > | this possible? | > | > Not directly. But you can say | > | > foo (MkC x) = foo' x | > | > foo' :: forall a. C a => a -> ... | > foo' x = ... | > {-# SPECIALISE foo' :: Int -> ... #-} | > | > There's no built-in mechanism I'm afraid. | > | > Simon | > | > _______________________________________________ | > Glasgow-haskell-users mailing list | > Glasgow-haskell-users@haskell.org | > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users | > | |

Let me ask this question in the abstract, lest I embarrass myself publicly with my shoddy code: Suppose I find that -p style profiling with -auto-all attributes the majority of the cost of my program to a single function. Naturally, I'd like to refine this somewhat. So I add additional cost centres as follows: f a1 ... an = e where d1 = {-# SCC "d1" #-} e1 ... d1 = {-# SCC "dn" #-} e1 I find it's still attributing almost all of the cost to the original CC (f), so I add another SCC, before the RHS. And it _still_ attributes the same amount to f, and effectively nothing to the body CC. So my questions are firstly, can someone explain this; and secondly, is there a style of adding CCs that would be more informative in such cases? (Or if it comes down to it, transforming the code to be more revelatory in that respect.) Cheers, Alex.
participants (2)
-
Alex Ferguson
-
Simon Peyton-Jones