[Hat] Qualified variable in pattern: T.mkRoot
Malcolm Wallace
Malcolm.Wallace at cs.york.ac.uk
Wed Jun 29 08:37:25 EDT 2005
Thomas Davie <tatd2 at kent.ac.uk> writes:
> > Just foo = undefined
>
> The haskell syntax states:
>
> decl -> gendecl
> | (funlhs | pat0) rhs
>
> where, gendecl covers type definitions, funlhs covers functions (and
> must start with a lower case character), and pat0 covers 0 arity
> patterns.
The notation pat_0 does not mean zero-arity, but zero-fixity. Thus,
since any pat_i can be a pat_i+1, and
pat_10 -> apat
| gcon apat_1 ... apat_k
the given declaration is syntactically valid, even though it is
certainly unusual.
hat-trans is generating bad code for this, because the pattern binding
is at the toplevel. If the pattern binding were in a let or where
clause, the generated code is different. When not at the toplevel,
the parent, p, of the binding is always a variable passed in.
But at the toplevel, there is no static parent, so hat-trans has
wrongly substituted T.mkRoot (which explicitly represents no parent),
in both the generated pattern and the generated expression:
gx px T.mkRoot = T.constUse px T.mkRoot sx -- incorrect
vs.
gx px p = T.constUse px p sx -- correct
I think the attached patch for hat-trans should fix the problem (but
would like someone to confirm this is not going to break anything else,
before I will commit it to CVS).
Regards,
Malcolm
-------------- next part --------------
Index: TraceTrans.hs
===================================================================
RCS file: /home/cvs/root/hat/src/hattrans/TraceTrans.hs,v
retrieving revision 1.73
diff -u -r1.73 src/hattrans/TraceTrans.hs
--- src/hattrans/TraceTrans.hs 27 Sep 2004 11:15:51 -0000 1.73
+++ src/hattrans/TraceTrans.hs 29 Jun 2005 12:34:34 -0000
@@ -701,13 +701,14 @@
(Fun [pat'] (Unguarded exp') decls',altConsts) =
tFun traced False parent failContinuation (Fun [pat] rhs decls)
useSR = ExpVar pos (nameSR firstId)
+ useParent = ExpVar pos nameParent
useDef :: (Pos,TraceId) -> Decl TokenId
useDef (pos,id) =
DeclFun pos (nameTransLetVar id)
- [Fun [useSR,parent]
+ [Fun [useSR,useParent]
(Unguarded (ExpApplication pos
- [combConstUse pos traced,useSR,parent,ExpVar pos (nameShare id)]))
+ [combConstUse pos traced,useSR,useParent,ExpVar pos (nameShare id)]))
noDecls]
projDef :: (Pos,TraceId) -> Decl TokenId
More information about the Hat
mailing list