Exemplo n.º 1
0
            internal term Canonicalize(term term)
            {
                switch (term.Kind)
                {
                case TermKind.Atom: return(term);

                case TermKind.Apply: return(term.Apply(Canonicalize(term.ApplyF), Canonicalize(term.ApplyX)));

                case TermKind.Var:
                    atom existing;
                    if (_canonicalName.TryGetValue(term.VarName, out existing))
                    {
                        return(term.Var(existing));
                    }
                    return(term.Var(_canonicalName[term.VarName] = new atom("var_" + (++_counter))));
                }
                throw new Exception("unreachable path");
            }
Exemplo n.º 2
0
        private term Unfree(term term)
        {
            switch (term.Kind)
            {
            case TermKind.Atom: return(term);

            case TermKind.Apply: return(term.Apply(Unfree(term.ApplyF), Unfree(term.ApplyX)));

            case TermKind.Var: return(Generate(term.VarName, (a, x, y) => term.Var(new atom(a.Value + "_" + x))));    // TODO: This should be a utility op in atom
            }
            throw new Exception("unreachable case");
        }