[Change Id's from Ints to An abstract data type
John Meacham <john@repetae.net>**20090219092724
 Ignore-this: 1ac97553f48a603b69cf99bb7c639fa1
] hunk ./DataConstructors.hs 87
-    return $ EPi (tVr 0 (t1')) t2'
+    return $ EPi (tVr emptyId (t1')) t2'
hunk ./DataConstructors.hs 97
-        v <- newName [70,72..] () tv
+        v <- newName (map anonymous [70,72..]) () tv
hunk ./DataConstructors.hs 114
-kind (Kfun k1 k2) = EPi (tVr 0 (kind k1)) (kind k2)
+kind (Kfun k1 k2) = EPi (tVr emptyId (kind k1)) (kind k2)
hunk ./DataConstructors.hs 237
-        typeVars = take n [ tvr { tvrType = eStar, tvrIdent = v } | v <- [ 2,4 ..]]
-        vars =  [ tvr { tvrType = EVar t, tvrIdent = v } | v <- [ 2*n + 16, 2*n + 18 ..] | t <- typeVars ]
+        typeVars = take n [ tvr { tvrType = eStar, tvrIdent = v } | v <- map anonymous [ 2,4 ..]]
+        vars =  [ tvr { tvrType = EVar t, tvrIdent = v } | v <- map anonymous [ 2*n + 16, 2*n + 18 ..] | t <- typeVars ]
hunk ./DataConstructors.hs 240
-        dtipe = foldr EPi (foldr EPi ftipe [ v { tvrIdent = 0 } | v <- vars]) typeVars
+        dtipe = foldr EPi (foldr EPi ftipe [ v { tvrIdent = emptyId } | v <- vars]) typeVars
hunk ./DataConstructors.hs 265
-            conType = EPi (tVr 0 eStar) (EPi (tVr 0 eStar) eStar),
+            conType = EPi (tVr emptyId eStar) (EPi (tVr emptyId eStar) eStar),
hunk ./DataConstructors.hs 267
-            conExpr = ELam (tVr 2 eStar) (ELam (tVr 4 eStar) (EPi (tVr 0 (EVar $ tVr 2 eStar)) (EVar $ tVr 4 eStar))),
+            conExpr = ELam (tVr id2 eStar) (ELam (tVr id4 eStar) (EPi (tVr emptyId (EVar $ tVr id2 eStar)) (EVar $ tVr id4 eStar))),
hunk ./DataConstructors.hs 270
-        }
+        } where id2 = anonymous 2 ; id4 = anonymous 4
hunk ./DataConstructors.hs 287
-            conExpr = ELam (tVr 2 rt) (ELit (litCons { litName = dc, litArgs = [EVar (tVr 2 rt)], litType = tipe })),
+            conExpr = ELam (tVr (anonymous 2) rt) (ELit (litCons { litName = dc, litArgs = [EVar (tVr (anonymous 2) rt)], litType = tipe })),
hunk ./DataConstructors.hs 304
-typesCompatable dataTable a b = f (-2 :: Id) a b where
-        f :: Id -> E -> E -> m ()
+typesCompatable dataTable a b = f etherealIds a b where
+        f :: [Id] -> E -> E -> m ()
hunk ./DataConstructors.hs 322
-        f c (EPi (TVr { tvrIdent = 0, tvrType =  a}) b) (ELit (LitCons { litName = n, litArgs = [a',b'], litType = t })) | conName tarrow == n, t == eStar = do
+        f c (EPi (TVr { tvrIdent = eid, tvrType =  a}) b) (ELit (LitCons { litName = n, litArgs = [a',b'], litType = t })) | eid == emptyId, conName tarrow == n, t == eStar = do
hunk ./DataConstructors.hs 325
-        f c (ELit (LitCons { litName = n, litArgs = [a',b'], litType = t })) (EPi (TVr { tvrIdent = 0, tvrType =  a}) b)  | conName tarrow == n, t == eStar = do
+        f c (ELit (LitCons { litName = n, litArgs = [a',b'], litType = t })) (EPi (TVr { tvrIdent = eid, tvrType =  a}) b)  | eid == emptyId, conName tarrow == n, t == eStar = do
hunk ./DataConstructors.hs 331
-        lam :: TVr -> E -> TVr -> E -> Id -> m ()
-        lam va ea vb eb c = do
-            f c (tvrType va) (tvrType vb)
-            f (c - 2) (subst va (EVar va { tvrIdent = c }) ea) (subst vb (EVar vb { tvrIdent = c }) eb)
+        lam :: TVr -> E -> TVr -> E -> [Id] -> m ()
+        lam va ea vb eb ~(c:cs) = do
+            f (c:cs) (tvrType va) (tvrType vb)
+            f cs (subst va (EVar va { tvrIdent = c }) ea) (subst vb (EVar vb { tvrIdent = c }) eb)
hunk ./DataConstructors.hs 475
-        v1 = tvr { tvrIdent = 2,  tvrType = typ }
-        v2 = tvr { tvrIdent = 4,  tvrType = typ }
-        i1 = tvr { tvrIdent = 6,  tvrType = it }
-        i2 = tvr { tvrIdent = 8,  tvrType = it }
-        b3 = tvr { tvrIdent = 10, tvrType = tBoolzh }
-        val1 = tvr { tvrIdent = 14, tvrType = typ }
+        v1 = tvr { tvrIdent = anonymous 2,  tvrType = typ }
+        v2 = tvr { tvrIdent = anonymous 4,  tvrType = typ }
+        i1 = tvr { tvrIdent = anonymous 6,  tvrType = it }
+        i2 = tvr { tvrIdent = anonymous 8,  tvrType = it }
+        b3 = tvr { tvrIdent = anonymous 10, tvrType = tBoolzh }
+        val1 = tvr { tvrIdent = anonymous 14, tvrType = typ }
hunk ./DataConstructors.hs 535
-        return (foldr ELam sl [ tVr i s | s <- getSlots cs | i <- [2,4..]])
+        return (foldr ELam sl [ tVr (anonymous i) s | s <- getSlots cs | i <- [2,4..]])
hunk ./DataConstructors.hs 574
-            dataCons = fc { conName = consName, conType = getType (conExpr dataCons), conOrigSlots = [SlotNormal rtype], conExpr = ELam (tVr 12 rtype) (ELit (litCons { litName = consName, litArgs = [EVar (tVr 12 rtype)], litType =  conExpr theType })) }
+            dataCons = fc { conName = consName, conType = getType (conExpr dataCons), conOrigSlots = [SlotNormal rtype], conExpr = ELam (tVr (anonymous 12) rtype) (ELit (litCons { litName = consName, litArgs = [EVar (tVr (anonymous 12) rtype)], litType =  conExpr theType })) }
hunk ./DataConstructors.hs 607
-        strictize tslots con = E.Subst.subst tvr { tvrIdent = -1 } Unknown $ f tslots con where
+        strictize tslots con = E.Subst.subst tvr { tvrIdent = anonymous $ -1 } Unknown $ f tslots con where
hunk ./DataConstructors.hs 617
-            mapM_ (newName [2,4..] ()) vs
+            mapM_ (newName (map anonymous [2,4..]) ()) vs
hunk ./DataConstructors.hs 619
-        subst = substMap $ fromList [ (tvrIdent tv ,EVar $ tv { tvrIdent = p }) | EVar tv <- thisTypeArgs | p <- [2,4..] ]
+        subst = substMap $ fromList [ (tvrIdent tv ,EVar $ tv { tvrIdent = p }) | EVar tv <- thisTypeArgs | p <- map anonymous [2,4..] ]
hunk ./DataConstructors.hs 640
-            fvset = freeVars (thisTypeArgs,origArgs) `mappend` fromList [2,4 .. 2 * (length theTypeArgs + 2)]
+            fvset = freeVars (thisTypeArgs,origArgs) `mappend` fromList (map anonymous [2,4 .. 2 * (length theTypeArgs + 2)])
hunk ./DataConstructors.hs 654
-        theTypeArgs = [ tvr { tvrIdent = x } | tvr  <- theTypeKArgs' | x <- [2,4..] ]
+        theTypeArgs = [ tvr { tvrIdent = x } | tvr  <- theTypeKArgs' | x <- map anonymous [2,4..] ]
hunk ./DataConstructors.hs 689
-    sub = substMap $ fromDistinctAscList [ (i,sl) | sl <- xs | i <- [2,4..] ]
+    sub = substMap $ fromDistinctAscList [ (anonymous i,sl) | sl <- xs | i <- [2,4..] ]
hunk ./DataConstructors.hs 712
-                            return $ tVr (2*s) t
+                            return $ tVr (anonymous $ 2*s) t
hunk ./DataConstructors.hs 731
-    sub = substMap $ fromDistinctAscList [ (i,sl) | sl <- xs | i <- [2,4..] ]
+    sub = substMap $ fromDistinctAscList [ (anonymous i,sl) | sl <- xs | i <- [2,4..] ]
hunk ./DataConstructors.hs 748
-    sub = substMap $ fromDistinctAscList [ (i,sl) | sl <- xs | i <- [2,4..] ]
+    sub = substMap $ fromDistinctAscList [ (anonymous i,sl) | sl <- xs | i <- [2,4..] ]
hunk ./DataConstructors.hs 816
-    f (EPi (TVr { tvrIdent = 0, tvrType = t1 }) t2) = do
+    f (EPi (TVr { tvrIdent = eid, tvrType = t1 }) t2) | eid == emptyId = do
hunk ./E/Annotate.hs 124
-    lp bnd lam tvr@(TVr { tvrIdent = n, tvrType = t}) e | n == 0  = do
+    lp bnd lam tvr@(TVr { tvrIdent = n, tvrType = t}) e | n == emptyId  = do
hunk ./E/Annotate.hs 129
-        return $ lam (tvr { tvrIdent =  0, tvrType =  t', tvrInfo =  nfo}) e'
+        return $ lam (tvr { tvrIdent = emptyId, tvrType =  t', tvrInfo =  nfo}) e'
hunk ./E/Annotate.hs 141
-    ntvr xs tvr@(TVr { tvrIdent = 0, tvrType =  t}) = do
+    ntvr xs tvr@(TVr { tvrIdent = n, tvrType =  t}) | n == emptyId = do
hunk ./E/Annotate.hs 143
-        nfo <- lift $ idann 0 (tvrInfo tvr)
+        nfo <- lift $ idann emptyId (tvrInfo tvr)
hunk ./E/Binary.hs 8
+import Name.Id
hunk ./E/Binary.hs 12
+
hunk ./E/Binary.hs 17
-    put (TVr { tvrIdent = 0, tvrType =  e, tvrInfo = nf} ) = do
+    put (TVr { tvrIdent = eid, tvrType =  e, tvrInfo = nf} ) | eid == emptyId = do
hunk ./E/Binary.hs 21
-    put (TVr { tvrIdent = i, tvrType =  e, tvrInfo = nf}) | Just x <- intToAtom i = do
+    put (TVr { tvrIdent = i, tvrType =  e, tvrInfo = nf}) | Just x <- intToAtom (idToInt i) = do
hunk ./E/Binary.hs 26
-        put (TvrBinaryInt $ fromIntegral i)
+        put (TvrBinaryInt $ fromIntegral (idToInt i))
hunk ./E/Binary.hs 34
-            TvrBinaryNone -> return $ TVr 0 e nf
+            TvrBinaryNone -> return $ TVr emptyId e nf
hunk ./E/Binary.hs 36
-            TvrBinaryInt i -> return $ TVr (fromIntegral i) e nf
+            TvrBinaryInt i -> return $ TVr (anonymous $ fromIntegral i) e nf
hunk ./E/Demand.hs 231
-isEmptyId 0 = True
-isEmptyId _ = False
hunk ./E/Demand.hs 307
-analyze (ELam x@TVr { tvrIdent = 0 } e) (S (Product [s])) = do
+analyze (ELam x@TVr { tvrIdent = eid } e) (S (Product [s])) | eid == emptyId = do
hunk ./E/E.hs 68
-tFunc a b = ePi (tVr 0 a) b
+tFunc a b = ePi (tVr emptyId a) b
hunk ./E/E.hs 74
-tvrSilly = tVr ((-1)) Unknown
+tvrSilly = tVr (anonymous (-1)) Unknown
hunk ./E/Eta.hs 177
-        if tvrIdent t == 0
+        if tvrIdent t == emptyId
hunk ./E/Eta.hs 186
-        if tvrIdent t == 0
+        if tvrIdent t == emptyId
hunk ./E/Eta.hs 202
-    r <- etaExpandDef dataTable 0 tvr { tvrIdent = 0} (foldl EAp (EVar tvr) xs)
+    r <- etaExpandDef dataTable 0 tvr { tvrIdent = emptyId} (foldl EAp (EVar tvr) xs)
hunk ./E/Eval.hs 15
+import Name.Id
hunk ./E/Eval.hs 85
-    eval' _ds (EVar TVr { tvrIdent = 0 }) _stack = fail "empty ident in term"
+    eval' _ds (EVar TVr { tvrIdent = eid }) _stack | eid == emptyId = fail "empty ident in term"
hunk ./E/FreeVars.hs 27
-instance FreeVars E [Int] where
+instance FreeVars E [Id] where
hunk ./E/FromHs.hs 50
+import Name.Id
hunk ./E/FromHs.hs 84
-        f xs (tVr (2*s) x:ys)
+        f xs (tVr (anonymous $ 2*s) x:ys)
hunk ./E/FromHs.hs 89
-    f (TArrow t1 t2) =  EPi (tVr 0 (f t1)) (f t2)
+    f (TArrow t1 t2) =  EPi (tVr emptyId (f t1)) (f t2)
hunk ./E/FromHs.hs 110
-kind (Kfun k1 k2) = EPi (tVr 0 (kind k1)) (kind k2)
+kind (Kfun k1 k2) = EPi (tVr emptyId (kind k1)) (kind k2)
hunk ./E/FromHs.hs 184
-            worldVar = tvr { tvrIdent = 2, tvrType = tWorld__ }
+            worldVar = tvr { tvrIdent = anonymous 2, tvrType = tWorld__ }
hunk ./E/FromHs.hs 202
-            ts' = [ EVar (tVr j (getType z)) | z <- ts | j <- [2,4 ..], j `notElem` map tvrIdent args]
+            ts' = [ EVar (tVr j (getType z)) | z <- ts | j' <- [2,4 ..], let j = anonymous j', j `notElem` map tvrIdent args]
hunk ./E/FromHs.hs 207
-            (ja:jb:_) = [ j |  j <- [2,4 ..], j `notElem` map tvrIdent args]
+            (ja:jb:_) = [ anonymous j |  j <- [2,4 ..], anonymous j `notElem` map tvrIdent args]
hunk ./E/FromHs.hs 243
-unbox :: DataTable -> E -> Int -> (E -> E) -> E
+unbox :: DataTable -> E -> Id -> (E -> E) -> E
hunk ./E/LambdaLift.hs 65
-        newV = foldr ELam (EVar tvr') [ t { tvrIdent = 0 } | t <- droppedAs ]
+        newV = foldr ELam (EVar tvr') [ t { tvrIdent = emptyId } | t <- droppedAs ]
hunk ./E/LambdaLift.hs 281
-        globalName tvr | not $ isValidAtom (tvrIdent tvr) = do
+        globalName tvr | isNothing $ fromId (tvrIdent tvr) = do
hunk ./E/LetFloat.hs 58
-    f ep@(EPi tvr@TVr {tvrIdent = i, tvrType = t} b) | i == 0 || i `notMember` freeIds b  = do
+    f ep@(EPi tvr@TVr {tvrIdent = i, tvrType = t} b) | i == emptyId || i `notMember` freeIds b  = do
hunk ./E/LetFloat.hs 61
-        dl (\ [t,b] -> EPi tvr { tvrIdent = 0, tvrType = t } b) [t,b]
+        dl (\ [t,b] -> EPi tvr { tvrIdent = emptyId, tvrType = t } b) [t,b]
hunk ./E/PrimOpt.hs 44
-unbox :: DataTable -> E -> Int -> (TVr -> E) -> E
+unbox :: DataTable -> E -> Id -> (TVr -> E) -> E
hunk ./E/Program.hs 10
-import StringTable.Atom
hunk ./E/Program.hs 88
-        | any (not . isValidAtom) (map combIdent ds) = error $ "programSetDs: trying to set non unique top level name: \n" ++ names
+        | any (not . isJust . fromId) (map combIdent ds) = error $ "programSetDs: trying to set non unique top level name: \n" ++ names
hunk ./E/Rules.hs 248
-match lup vs = \e1 e2 -> liftM Seq.toList $ execWriterT (un e1 e2 () (-2::Int)) where
+match lup vs = \e1 e2 -> liftM Seq.toList $ execWriterT (un e1 e2 () etherealIds) where
hunk ./E/Rules.hs 268
-    un (EVar TVr { tvrIdent = i, tvrType =  t}) (EVar TVr {tvrIdent = j, tvrType =  u}) mm c | i < 0 || j < 0  = fail "Expressions don't match"
+    un (EVar TVr { tvrIdent = i, tvrType =  t}) (EVar TVr {tvrIdent = j, tvrType =  u}) mm c | isEtherealId i || isEtherealId j  = fail "Expressions don't match"
hunk ./E/Rules.hs 275
-    lam va ea vb eb mm c = do
-        un (tvrType va) (tvrType vb) mm c
-        un (subst va (EVar va { tvrIdent = c }) ea) (subst vb (EVar vb { tvrIdent = c }) eb) mm (c - 2)
+    lam va ea vb eb mm ~(c:cs) = do
+        un (tvrType va) (tvrType vb) mm (c:cs)
+        un (subst va (EVar va { tvrIdent = c }) ea) (subst vb (EVar vb { tvrIdent = c }) eb) mm cs
hunk ./E/SSimplify.hs 119
-    f (EPi tvr@TVr { tvrIdent = 0, tvrType =  a} b) = arg $ do
+    f (EPi tvr@TVr { tvrIdent = eid, tvrType =  a} b) | isEmptyId eid = arg $ do
hunk ./E/SSimplify.hs 127
-            Nothing -> tell (tfvs,mempty) >>  return (EPi tvr { tvrIdent =  0, tvrType = a } b)
+            Nothing -> tell (tfvs,mempty) >>  return (EPi tvr { tvrIdent =  emptyId, tvrType = a } b)
hunk ./E/SSimplify.hs 198
-    Nothing | sortTermLike (getType tvr) -> annb' tvr { tvrIdent = 0 }
+    Nothing | sortTermLike (getType tvr) -> annb' tvr { tvrIdent = emptyId }
hunk ./E/SSimplify.hs 203
-    Nothing -> annb notUsedInfo tvr { tvrIdent = 0 }
+    Nothing -> annb notUsedInfo tvr { tvrIdent = emptyId }
hunk ./E/SSimplify.hs 381
-insertSuspSubst' 0 _e env = env
+insertSuspSubst' z _e env | isEmptyId z = env
hunk ./E/SSimplify.hs 385
-insertRange 0 e env = env
+insertRange z e env | isEmptyId z = env
hunk ./E/SSimplify.hs 392
-insertDoneSubst' 0 _e env = env
+insertDoneSubst' z _e env | isEmptyId z = env
hunk ./E/SSimplify.hs 397
-insertInScope 0 _b env = env
+insertInScope z _b env | isEmptyId z = env
hunk ./E/SSimplify.hs 568
-    showName t | isValidAtom t || dump FD.EVerbose = tvrShowName (tVr t Unknown)
+    showName t | isJust (fromId t) || dump FD.EVerbose = tvrShowName (tVr t Unknown)
hunk ./E/SSimplify.hs 576
-        n' <- if n == 0 then return 0 else uniqueName n
+        n' <- if n == emptyId then return emptyId else uniqueName n
hunk ./E/SSimplify.hs 685
-            doCase e _ TVr { tvrIdent = 0 } [] (Just d) | isOmittable inb e = do
+            doCase e _ TVr { tvrIdent = z } [] (Just d) | isEmptyId z, isOmittable inb e = do
hunk ./E/SSimplify.hs 701
-                    (EVar v,0) -> do
+                    (EVar v,z) | isEmptyId z -> do
hunk ./E/SSimplify.hs 724
-                    mins _ e | 0 `notMember` (freeVars e :: IdSet) = insertInScope (tvrIdent b') (isBoundTo noUseInfo e)
+                    mins _ e | emptyId `notMember` (freeVars e :: IdSet) = insertInScope (tvrIdent b') (isBoundTo noUseInfo e)
hunk ./E/SSimplify.hs 757
-                let bs' = [ x | x@(TVr { tvrIdent = n },_) <- bs, n /= 0]
+                let bs' = [ x | x@(TVr { tvrIdent = n },_) <- bs, n /= emptyId]
hunk ./E/SSimplify.hs 1076
-        newNameFrom (filter (>0) $ filter even $ randoms g2)
+        newNameFrom (map anonymous $ filter (>0) $ filter even $ randoms g2)
hunk ./E/Show.hs 40
-showId 0 = (char '_')
+showId e | e == emptyId = (char '_')
hunk ./E/Show.hs 136
-allocTVr tvr action | tvrIdent tvr == 0 = action
+allocTVr tvr action | tvrIdent tvr == emptyId = action
hunk ./E/Show.hs 141
-allocTVr tvr (SEM action) | not $ isValidAtom (tvrIdent tvr) = do
+allocTVr tvr (SEM action) | not $ isJust (fromId (tvrIdent tvr)) = do
hunk ./E/Show.hs 149
-    go e1@(EPi tvr e)  xs | tvrIdent tvr == 0                = done e1 xs
+    go e1@(EPi tvr e)  xs | tvrIdent tvr == emptyId          = done e1 xs
hunk ./E/Show.hs 181
-        f (EPi (TVr { tvrIdent = 0, tvrType =  e1}) e2) = liftM2 arr (showE e1) (showE e2)
+        f (EPi (TVr { tvrIdent = eid, tvrType =  e1}) e2) | eid == emptyId = liftM2 arr (showE e1) (showE e2)
hunk ./E/Show.hs 219
-            db <- showTVr (if dump FD.EVerbose || isUsed then ecb else ecb { tvrIdent = 0 })
+            db <- showTVr (if dump FD.EVerbose || isUsed then ecb else ecb { tvrIdent = emptyId })
hunk ./E/Subst.hs 58
-eLetRec ds e = f (filter ((/= 0) . tvrIdent . fst) ds) where
+eLetRec ds e = f (filter ((/= emptyId) . tvrIdent . fst) ds) where
hunk ./E/Subst.hs 69
-subst (TVr { tvrIdent = 0 }) _ e = e
+subst (TVr { tvrIdent = eid }) _ e | eid == emptyId = e
hunk ./E/Subst.hs 79
-subst' (TVr { tvrIdent = 0 }) _ e = e
+subst' (TVr { tvrIdent = eid }) _ e | eid == emptyId = e
hunk ./E/Subst.hs 151
-    lp lam tvr@(TVr { tvrIdent = n, tvrType = t}) e | n == 0 || (allShadow && n `notElem` freeVars e) = do
+    lp lam tvr@(TVr { tvrIdent = n, tvrType = t}) e | n == emptyId || (allShadow && n `notElem` freeVars e) = do
hunk ./E/Subst.hs 154
-        return $ lam (tvr { tvrIdent =  0, tvrType =  t'}) e'
+        return $ lam (tvr { tvrIdent =  emptyId, tvrType =  t'}) e'
hunk ./E/Subst.hs 166
-    ntvr xs tvr@(TVr { tvrIdent = 0, tvrType =  t}) = do
+    ntvr xs tvr@(TVr { tvrIdent = eid, tvrType =  t}) | eid == emptyId = do
hunk ./E/Subst.hs 190
-eAp (EPi t b) e = if tvrIdent t == 0 then b else subst t e b
-eAp (ELam t b) e = if tvrIdent t == 0 then b else subst t e b
+eAp (EPi t b) e = if tvrIdent t == emptyId then b else subst t e b
+eAp (ELam t b) e = if tvrIdent t == emptyId then b else subst t e b
hunk ./E/Subst.hs 259
-    lp lam tvr@(TVr { tvrIdent = 0, tvrType = t}) e  = do
+    lp lam tvr@(TVr { tvrIdent = eid, tvrType = t}) e | eid == emptyId = do
hunk ./E/Subst.hs 262
-        return $ lam (tvr { tvrIdent =  0, tvrType =  t'}) e'
+        return $ lam (tvr { tvrIdent =  emptyId, tvrType =  t'}) e'
hunk ./E/Subst.hs 283
-    ntvr xs tvr@(TVr { tvrIdent = 0, tvrType =  t}) = do
+    ntvr xs tvr@(TVr { tvrIdent = eid, tvrType =  t}) | eid == emptyId = do
hunk ./E/Traverse.hs 20
-import StringTable.Atom
hunk ./E/Traverse.hs 151
-    ntvr _ fg tv@TVr { tvrIdent = 0, tvrType = t} = do
+    ntvr _ fg tv@TVr { tvrIdent = eid, tvrType = t} | eid == emptyId = do
hunk ./E/Traverse.hs 156
-        n' <- if not (isEtherialId n) && (not ralways || isValidAtom n) then uniqueName  n else newName
+        n' <- if not (isEtherealId n) && (not ralways || isJust (fromId n)) then uniqueName  n else newName
hunk ./E/Type.hs 188
-    showsPrec n TVr { tvrIdent = 0, tvrType = e} = showParen (n > 10) $ showString "_::" . shows e
+    showsPrec n TVr { tvrIdent = eid, tvrType = e} | eid == emptyId = showParen (n > 10) $ showString "_::" . shows e
hunk ./E/Type.hs 233
-patToLitEE LitCons { litName = n, litArgs = [a,b], litType = t } | t == eStar, n == tc_Arrow = EPi (tVr 0 (EVar a)) (EVar b)
+patToLitEE LitCons { litName = n, litArgs = [a,b], litType = t } | t == eStar, n == tc_Arrow = EPi (tVr emptyId (EVar a)) (EVar b)
hunk ./E/Type.hs 277
-tvr = TVr { tvrIdent = 0, tvrType = Unknown, tvrInfo = Info.empty }
+tvr = TVr { tvrIdent = emptyId, tvrType = Unknown, tvrInfo = Info.empty }
hunk ./E/TypeAnalysis.hs 265
-repi (ELit LitCons { litName = n, litArgs = [a,b] }) | n == tc_Arrow = EPi tvr { tvrIdent = 0, tvrType = repi a } (repi b)
+repi (ELit LitCons { litName = n, litArgs = [a,b] }) | n == tc_Arrow = EPi tvr { tvrIdent = emptyId, tvrType = repi a } (repi b)
hunk ./E/TypeAnalysis.hs 412
-            eCaseBind = a { tvrIdent = 0 },
+            eCaseBind = a { tvrIdent = emptyId },
hunk ./E/TypeCheck.hs 211
-    fc (EVar (TVr { tvrIdent = 0 })) = fail "variable with nothing!"
+    fc (EVar (TVr { tvrIdent = eid })) | eid == emptyId = fail "variable with nothing!"
hunk ./E/TypeCheck.hs 230
-        let ck (TVr { tvrIdent = 0 },_) = fail "binding of empty var"
+        let ck (TVr { tvrIdent = eid },_) | eid == emptyId = fail "binding of empty var"
hunk ./E/TypeCheck.hs 281
-    verifyPats' LitCons { litArgs = xs } = when (hasRepeatUnder id (filter (/= 0) $ map tvrIdent xs)) $ fail "Case pattern is non-linear"
+    verifyPats' LitCons { litArgs = xs } = when (hasRepeatUnder id (filter (/= emptyId) $ map tvrIdent xs)) $ fail "Case pattern is non-linear"
hunk ./E/TypeCheck.hs 370
-    fc (EVar TVr { tvrIdent = 0 }) = fail "variable with nothing!"
+    fc (EVar TVr { tvrIdent = eid }) | eid == emptyId = fail "variable with nothing!"
hunk ./E/TypeCheck.hs 404
-    fc (EVar TVr { tvrIdent = 0 }) = fail "variable with nothing!"
+    fc (EVar TVr { tvrIdent = eid }) | eid == emptyId = fail "variable with nothing!"
hunk ./E/TypeCheck.hs 443
-match lup vs = \e1 e2 -> liftM Seq.toList $ execWriterT (un e1 e2 () (-2::Int)) where
+match lup vs = \e1 e2 -> liftM Seq.toList $ execWriterT (un e1 e2 () etherealIds) where
hunk ./E/TypeCheck.hs 463
-    un (EVar TVr { tvrIdent = i, tvrType =  t}) (EVar TVr {tvrIdent = j, tvrType =  u}) mm c | i < 0 || j < 0  = fail "Expressions don't match"
+    un (EVar TVr { tvrIdent = i, tvrType =  t}) (EVar TVr {tvrIdent = j, tvrType =  u}) mm c | isEtherealId i || isEtherealId j   = fail "Expressions don't match"
hunk ./E/TypeCheck.hs 470
-    lam va ea vb eb mm c = do
-        un (tvrType va) (tvrType vb) mm c
-        un (subst va (EVar va { tvrIdent = c }) ea) (subst vb (EVar vb { tvrIdent = c }) eb) mm (c - 2)
+    lam va ea vb eb mm (c:cs) = do
+        un (tvrType va) (tvrType vb) mm (c:cs)
+        un (subst va (EVar va { tvrIdent = c }) ea) (subst vb (EVar vb { tvrIdent = c }) eb) mm cs
hunk ./E/Values.hs 114
-eCaseTup e vs w = caseUpdate emptyCase { eCaseScrutinee = e, eCaseBind =  (tVr 0 (getType e)), eCaseType = getType w, eCaseAlts =  [Alt litCons { litName = nameTuple DataConstructor (length vs), litArgs = vs, litType = getType e } w] }
-eCaseTup' e vs w = caseUpdate emptyCase { eCaseScrutinee = e, eCaseBind = (tVr 0 (getType e)), eCaseType = getType w, eCaseAlts =  [Alt litCons { litName = unboxedNameTuple DataConstructor (length vs), litArgs = vs, litType = getType e} w] }
+eCaseTup e vs w = caseUpdate emptyCase { eCaseScrutinee = e, eCaseBind =  (tVr emptyId (getType e)), eCaseType = getType w, eCaseAlts =  [Alt litCons { litName = nameTuple DataConstructor (length vs), litArgs = vs, litType = getType e } w] }
+eCaseTup' e vs w = caseUpdate emptyCase { eCaseScrutinee = e, eCaseBind = (tVr emptyId (getType e)), eCaseType = getType w, eCaseAlts =  [Alt litCons { litName = unboxedNameTuple DataConstructor (length vs), litArgs = vs, litType = getType e} w] }
hunk ./E/Values.hs 120
-eCase e alts@(alt:_) Unknown = caseUpdate emptyCase { eCaseScrutinee = e, eCaseBind = (tVr 0 (getType e)), eCaseType = getType alt,  eCaseAlts =  alts }
-eCase e alts els = caseUpdate emptyCase { eCaseScrutinee = e, eCaseBind = (tVr 0 (getType e)), eCaseDefault = Just els, eCaseAlts =  alts, eCaseType = getType els }
+eCase e alts@(alt:_) Unknown = caseUpdate emptyCase { eCaseScrutinee = e, eCaseBind = (tVr emptyId (getType e)), eCaseType = getType alt,  eCaseAlts =  alts }
+eCase e alts els = caseUpdate emptyCase { eCaseScrutinee = e, eCaseBind = (tVr emptyId (getType e)), eCaseDefault = Just els, eCaseAlts =  alts, eCaseType = getType els }
hunk ./E/Values.hs 125
-eLet TVr { tvrIdent = 0 } _ e' = e'
+eLet TVr { tvrIdent = eid } _ e' | eid == emptyId = e'
hunk ./E/Values.hs 139
-    (as,nas) = partition (isAtomic . snd) (filter ((/= 0) . tvrIdent . fst) ds)
+    (as,nas) = partition (isAtomic . snd) (filter ((/= emptyId) . tvrIdent . fst) ds)
hunk ./E/Values.hs 147
-    nas = filter ((/= 0) . tvrIdent . fst) ds
+    nas = filter ((/= emptyId) . tvrIdent . fst) ds
hunk ./E/Values.hs 164
-prim_seq a b = caseUpdate emptyCase { eCaseScrutinee = a, eCaseBind =  (tVr 0 (getType a)), eCaseDefault = Just b, eCaseType = getType b }
+prim_seq a b = caseUpdate emptyCase { eCaseScrutinee = a, eCaseBind =  (tVr emptyId (getType a)), eCaseDefault = Just b, eCaseType = getType b }
hunk ./E/WorkerWrapper.hs 20
+import Name.Id
hunk ./E/WorkerWrapper.hs 49
-    g t@TVr { tvrIdent = 0 } _ = (Absent,t)
+    g t@TVr { tvrIdent = eid } _ | isEmptyId eid = (Absent,t)
hunk ./Grin/FromE.hs 309
-    conv (EPi (TVr { tvrIdent = 0, tvrType =  a}) b)  =  Const $ NodeC tagArrow [conv a,conv b]
+    conv (EPi (TVr { tvrIdent = z, tvrType =  a}) b) | isEmptyId z =  Const $ NodeC tagArrow [conv a,conv b]
hunk ./Grin/FromE.hs 337
-        ty -> Var (V num) ty
+        ty -> Var (V $ idToInt num) ty
hunk ./Grin/FromE.hs 497
-            v <- if tvrIdent b == 0 then newPrimVar $ TyPrim ty else return $ toVal b
+            v <- if tvrIdent b == emptyId then newPrimVar $ TyPrim ty else return $ toVal b
hunk ./Grin/FromE.hs 507
-            (TVr { tvrIdent = 0 },EVar etvr) -> localEvaled [etvr] v $ do
+            (TVr { tvrIdent = z },EVar etvr) | isEmptyId z -> localEvaled [etvr] v $ do
hunk ./Grin/FromE.hs 515
-            (TVr { tvrIdent = 0 },_) -> do
+            (TVr { tvrIdent = z },_) | isEmptyId z -> do
hunk ./Grin/FromE.hs 531
-        nm = fromList [ (tvrIdent x, v) | x <- vs, tvrIdent x /= 0 ]
+        nm = fromList [ (tvrIdent x, v) | x <- vs, tvrIdent x /= emptyId ]
hunk ./Grin/FromE.hs 700
-    constant (EPi (TVr { tvrIdent = 0, tvrType = a}) b) | Just a <- constant a, Just b <- constant b = return $ NodeC tagArrow [a,b]
+    constant (EPi (TVr { tvrIdent = z, tvrType = a}) b) | isEmptyId z, Just a <- constant a, Just b <- constant b = return $ NodeC tagArrow [a,b]
hunk ./Grin/FromE.hs 705
-    con (EPi (TVr {tvrIdent =  0, tvrType = x}) y) = do
+    con (EPi (TVr {tvrIdent =  z, tvrType = x}) y) | isEmptyId z = do
hunk ./Main.hs 680
-    f (ELam t@TVr { tvrIdent = v } e) | v /= 0, v `notMember` freeIds e = f (ELam t { tvrIdent = 0 } e)
-    f (EPi t@TVr { tvrIdent = v } e) | v /= 0, v `notMember` freeIds e = f (EPi t { tvrIdent = 0 } e)
-    f ec@ECase { eCaseBind = t@TVr { tvrIdent = v } } | v /= 0, v `notMember` (freeVars (caseBodies ec)::IdSet) = f ec { eCaseBind = t { tvrIdent = 0 } }
+    f (ELam t@TVr { tvrIdent = v } e) | v /= emptyId, v `notMember` freeIds e = f (ELam t { tvrIdent = emptyId } e)
+    f (EPi t@TVr { tvrIdent = v } e) | v /= emptyId, v `notMember` freeIds e = f (EPi t { tvrIdent = emptyId } e)
+    f ec@ECase { eCaseBind = t@TVr { tvrIdent = v } } | v /= emptyId, v `notMember` (freeVars (caseBodies ec)::IdSet) = f ec { eCaseBind = t { tvrIdent = emptyId } }
hunk ./Main.hs 935
-    let f (tvr@TVr { tvrIdent = n },e) | not $ isValidAtom n = do
+    let f (tvr@TVr { tvrIdent = n },e) | isNothing $ fromId n = do
hunk ./Name/Id.hs 13
-    etherialIds,
-    isEtherialId,
+    etherealIds,
+    isEtherealId,
hunk ./Name/Id.hs 16
+    isEmptyId,
hunk ./Name/Id.hs 29
+    toId,
+    fromId,
hunk ./Name/Id.hs 37
+import Data.Binary(Binary())
hunk ./Name/Id.hs 53
+import Doc.PPrint
+import Doc.DocLike
hunk ./Name/Id.hs 57
-type Id = Int
+newtype Id = Id Int
+    deriving(Eq,Ord,Enum,Binary)
hunk ./Name/Id.hs 61
-anonymous x = x
+anonymous x = Id x
hunk ./Name/Id.hs 67
-    deriving(Typeable,Monoid,HasSize,SetLike,BuildSet Id,ModifySet Id,IsEmpty,Eq,Ord)
+    deriving(Typeable,Monoid,HasSize,SetLike,IsEmpty,Eq,Ord)
+
+instance BuildSet Id IdSet where
+    fromList = idSetFromList
+    fromDistinctAscList = idSetFromDistinctAscList
+    insert (Id x) (IdSet b) = IdSet $ IS.insert x b
+    singleton (Id x) = IdSet $ IS.singleton x
+
+instance ModifySet Id IdSet where
+    toList = idSetToList
+    delete (Id x) (IdSet b) = IdSet $ IS.delete x b
+    member (Id x) (IdSet b) = IS.member x b
+    sfilter f (IdSet s) = IdSet $ IS.filter (f . Id) s
hunk ./Name/Id.hs 83
-idSetToList (IdSet is) = IS.toList is
+idSetToList (IdSet is) = [ Id x | x <- IS.toList is ]
hunk ./Name/Id.hs 86
-idMapToList (IdMap is) = IM.toList is
+idMapToList (IdMap is) = [ (Id x,y) | (x,y) <- IM.toList is ]
hunk ./Name/Id.hs 89
-idToInt = id
+idToInt (Id x) = x
hunk ./Name/Id.hs 98
-    deriving(Typeable,Monoid,HasSize,SetLike,BuildSet (Id,a),MapLike Id a,Functor,Traversable,Foldable,IsEmpty,Eq,Ord)
+    deriving(Typeable,Monoid,HasSize,SetLike,Functor,Traversable,Foldable,IsEmpty,Eq,Ord)
+
+instance BuildSet (Id,a) (IdMap a) where
+    fromList = idMapFromList
+    fromDistinctAscList = idMapFromDistinctAscList
+    insert (Id x,y) (IdMap b) = IdMap $ IM.insert x y b
+    singleton (Id x,y) = IdMap $ IM.singleton x y
+
+instance MapLike Id a (IdMap a) where
+    melems (IdMap m) = IM.elems m
+    mdelete (Id x) (IdMap m) = IdMap $ IM.delete x m
+    mmember (Id x) (IdMap m) = IM.member x m
+    mlookup (Id x) (IdMap m) = IM.lookup x m
+    massocs (IdMap m) = [ (Id x,y) | (x,y) <- IM.assocs m ]
+    mkeys (IdMap m) = [ Id x | x <- IM.keys m ]
+    mmapWithKey f (IdMap m) = IdMap $ IM.mapWithKey (\k v -> f (Id k) v) m
+    mfilter f (IdMap m) = IdMap $ IM.filter f m
+    mpartitionWithKey f (IdMap m) = case IM.partitionWithKey (\k v -> f (Id k) v) m of (x,y) -> (IdMap x,IdMap y)
+    munionWith f (IdMap m1) (IdMap m2) = IdMap $ IM.unionWith f m1 m2
+    mfilterWithKey f (IdMap m) = IdMap $ IM.filterWithKey (\k v -> f (Id k) v) m
+
+
hunk ./Name/Id.hs 123
-idSetToIdMap f (IdSet is) = IdMap $ IM.fromDistinctAscList [ (x,f x) |  x <- IS.toAscList is]
+idSetToIdMap f (IdSet is) = IdMap $ IM.fromDistinctAscList [ (x,f (Id x)) |  x <- IS.toAscList is]
hunk ./Name/Id.hs 178
-        let genNames i = [st, st + 2 ..]  where
+        let genNames i = map Id [st, st + 2 ..]  where
hunk ./Name/Id.hs 192
-idSetFromDistinctAscList ids = IdSet (IS.fromDistinctAscList ids)
+idSetFromDistinctAscList ids = IdSet (IS.fromDistinctAscList [ x | Id x <- ids] )
hunk ./Name/Id.hs 195
-idSetFromList ids = IdSet (IS.fromList ids)
+idSetFromList ids = IdSet (IS.fromList [ x | Id x <- ids])
hunk ./Name/Id.hs 198
-idMapFromList ids = IdMap (IM.fromList ids)
+idMapFromList ids = IdMap (IM.fromList [ (x,y) | (Id x,y) <- ids])
hunk ./Name/Id.hs 201
-idMapFromDistinctAscList ids = IdMap (IM.fromDistinctAscList ids)
+idMapFromDistinctAscList ids = IdMap (IM.fromDistinctAscList [ (x,y) | (Id x,y) <- ids ] )
+
hunk ./Name/Id.hs 205
+instance Show Id where
+        showsPrec _ n =  maybe (showString ('x':show (idToInt n))) shows (fromId n)
+    
+
hunk ./Name/Id.hs 211
-        f n =  maybe (toAtom ('x':show n)) (toAtom . show) (fromId n)
+        f n =  maybe (toAtom ('x':show (idToInt n))) (toAtom . show) (fromId n)
hunk ./Name/Id.hs 215
-        f (n,v) =  (maybe (toAtom ('x':show n)) (toAtom . show) (fromId n),v)
+        f (n,v) =  (maybe (toAtom ('x':show (idToInt n))) (toAtom . show) (fromId n),v)
hunk ./Name/Id.hs 223
-etherialIds :: [Id]
-etherialIds = [-2, -4 ..  ]
+etherealIds :: [Id]
+etherealIds = map Id [-2, -4 ..  ]
hunk ./Name/Id.hs 226
-isEtherialId id = id < 0
+isEtherealId id = id < emptyId
hunk ./Name/Id.hs 228
-isInvalidId id = id <= 0
+isInvalidId id = id <= emptyId
hunk ./Name/Id.hs 231
-emptyId = 0
+emptyId = Id 0
hunk ./Name/Id.hs 238
-newIds ids = [ i | i <- [s, s + 2 ..] , i `notMember` ids ] where
+newIds ids = [ Id i | i <- [s, s + 2 ..] , Id i `notMember` ids ] where
hunk ./Name/Id.hs 247
-    mask x = x .&. 0x0FFFFFFE
+    mask x = Id $ x .&. 0x0FFFFFFE
+
+
+
+toId :: Name -> Id
+toId x = Id $ fromAtom (toAtom x)
+
+instance FromAtom Id where
+    fromAtom x = Id $ fromAtom x
+
+fromId :: Monad m => Id -> m Name
+--fromId i | even i || i < 0 = fail $ "Name.fromId: not a name " ++ show i
+--fromId i | not $ isValidAtom i = fail $ "Name.fromId: not a name " ++ show i
+fromId (Id i) = case intToAtom i of
+    Just a -> return $ fromAtom a
+    Nothing -> fail $ "Name.fromId: not a name " ++ show i
hunk ./Name/Id.hs 264
+isEmptyId x = x == emptyId
hunk ./Name/Id.hs 266
+instance DocLike d => PPrint d Id where
+    pprint x = tshow x
hunk ./Name/Id.hs 269
+instance GenName Id where
+    genNames i = map Id [st, st + 2 ..]  where
+        st = abs i + 2 + abs i `mod` 2
hunk ./Name/Name.hs 15
-    toId,
-    fromId,
hunk ./Name/Name.hs 164
-toId :: Name -> Int
-toId x = fromAtom (toAtom x)
-
-fromId :: Monad m => Int -> m Name
---fromId i | even i || i < 0 = fail $ "Name.fromId: not a name " ++ show i
---fromId i | not $ isValidAtom i = fail $ "Name.fromId: not a name " ++ show i
-fromId i = case intToAtom i of
-    Just a -> return $ Name a
-    Nothing -> fail $ "Name.fromId: not a name " ++ show i