RE: specializing on existentially quantified data types

| 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

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
participants (2)
-
Lennart Augustsson
-
Simon Peyton-Jones