Generics and Substitution...
MR K P SCHUPKE
k.schupke at imperial.ac.uk
Wed Feb 4 11:00:25 EST 2004
I have used generics in a couple of places (from the
scrap your boilerplate paper) and want to know if it is
possible to write a function that will (for example) change
the types 'in place' in a type. For example replace all the
elements in a tuple with a string (using Show):
(3 :: Int,3.5 :: Float,True :: Bool) -> ("3" :: String,"3.5" :: String,"True" :: String)
Looking at the paper it seems a version of MkT with a different
type is required:
MkTT :: (Typeable a,Typeable b,Typeable c,Typeable d) => (c -> d) -> a -> b
You could then use:
subInt :: Int -> String
subInt i = showInt i ""
again everywhere has the wrong type so something like:
everywhere' :: (Term a,Term b) => (forall c.Term c,forall d.Term d => c -> d) -> a -> b
everywhere' f x = f (gmapTT (everywhere' f) x)
but can this "gmapTT" be defined in terms of "gfoldl"?
I tried to think about this... but I haven't quite got a handle
on gfoldl's type yet... Is it possible? Would the function look
like the definition of "gmapT" with a different type?
Regards,
Keean Schupke.
More information about the Glasgow-haskell-users
mailing list