specializing on existentially quantified data types
Simon Peyton-Jones
simonpj at microsoft.com
Tue Nov 25 09:20:08 EST 2003
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 at 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 at haskell.org
| > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
| >
|
|
More information about the Glasgow-haskell-users
mailing list