[Haskell-cafe] generics question, logical variables

Frederik Eaton frederik at a5.repetae.net
Mon Aug 29 00:35:39 EDT 2005

Hi all,

I'm trying to write something like a generic fmap, or a generic
natural transformation. The application is this. I have a typed
logical variable library which produces arbitrary terms with values of
type "Var a", which are references to a value of type "Maybe a", and I
want to write a "solve" function which replaces these values with
instantiated versions of type "Id a" where

newtype Id a = Id a

. Furthermore I want this to be reflected in the type of the generic

solve :: Pred (t Var) -> [t Id]

so if I have a type like

data Entry k = Entry (k String) (k Int)

then I can write some constraint equation with values of type "Entry
Var", and get back values of type "Entry Id" - in other words, objects
where the unknowns are statically guaranteed to have been filled in.

I looked at the generics library. I may be mistaken, but it seems that
it doesn't have what I need to do this. The problem isn't the mapping,
it's creating a new type which is parameterized by another type. The
only options for creating new types are variations on

fromConstr :: Data a => Constr -> a

but what is needed is something like

fromConstr1 :: Data1 a => Constr1 -> a b

With something like that it should be possible to define:

gmapT1 :: (forall b . Data1 b => b l -> b m) -> a l -> a m

Does this make sense? Here I would be treating all instances of Data
as possibly degenerate instances of Data1 (which just might not depend
on the type variable).

If it seems like a good idea, I would be interested in helping out
with the implementation.



More information about the Haskell-Cafe mailing list