QuickCheck invariants for AST transformations

I'm looking for suggestions on how to create invariants for the following AST transformation code. Any suggestions are appreciated! I asked this question before and Lennart suggested abstract interpretation as a solution. This would require interpreters for both ASTs to determine that the result they achieve is the same. I don't fancy writing a C# interpreter, though, so I'm looking for an easier way out. Thanks, Joel [1] http://tinyurl.com/368whq --- instance SharpTransform C.Type Type where toSharp C.TyInt = return TyInt toSharp C.TyFloat = return TyFloat toSharp C.TyStr = return TyStr toSharp C.TyBool = return TyBool toSharp (C.TyArray x) = liftM2 TyArray (toSharp x) (return []) toSharp (C.TySeries C.TyFloat) = return $ TyCustom "DataSeries" toSharp (C.TySeries x) = error $ "Unsupported series type: " ++ show x toSharp (C.TyProp x) = toSharp x toSharp C.TyUnit = return TyVoid instance SharpTransform C.VarIdent VarIdent where toSharp (C.VarIdent x) = return $ VarIdent x instance SharpTransform (Maybe C.Expr) (Maybe Expr) where toSharp Nothing = return Nothing toSharp (Just e) = liftM Just (toSharp e) instance SharpTransform C.Subscript [Expr] where toSharp xs = mapM toSharp xs instance SharpTransform C.BarsAgo Expr where toSharp C.Now = return $ Int 0 toSharp (C.BarsAgo e) = toSharp e -- http://wagerlabs.com/

On Tue, May 08, 2007 at 10:06:32AM +0100, Joel Reymont wrote:
I'm looking for suggestions on how to create invariants for the following AST transformation code. Any suggestions are appreciated!
I asked this question before and Lennart suggested abstract interpretation as a solution. This would require interpreters for both ASTs to determine that the result they achieve is the same. I don't fancy writing a C# interpreter, though, so I'm looking for an easier way out.
Thanks, Joel
You can't claim a translation preserves meaning, if you don't say anything about what C# means. But, you can use a description somebody else already wrote, like the microsoft implementation, or maybe there are formalizations floating around for some theorem provers. For partial specification, checking that a tranformation preserves types is good. If you're translating between languages you can at least define another translation between types, and check that the type of the translation of an expression is the translation of the expressions types. You still need a model of the C# type system, but you shouldn't need to trust the model if you generate code with type annotations, and any missmatches will be caught. You might avoid specifying the meaning of C# directly by instead assuming that certain pairs of expression and translation have the same meaning, whatever that is, and then use some other rules about when two expression in the same langauge are equivalent to stretch your primitive assumptions about translations to the correctness of your whole translation. How you show those rules are correct, I don't know. Brandon.
participants (2)
-
Brandon Michael Moore
-
Joel Reymont