23.11.2014 Views

2006 Scheme and Functional Programming Papers, University of

2006 Scheme and Functional Programming Papers, University of

2006 Scheme and Functional Programming Papers, University of

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

(term ’lam<br />

(lambda (x)<br />

(if (equal? x (Q 1)) (Q 2) (Q 3))))<br />

but it is not a valid representation — there is no lambda term<br />

that has this as its quotation. Briefly, the problem is that the<br />

function is trying to inspect its values (it would have been a<br />

valid representation had the whole if expression been quoted).<br />

This means that we should not allow arbitrary functions into<br />

the representation; indeed, major research efforts went into<br />

formalizing types in various ways from permutations-based<br />

approaches [15, 16, 17], to modal logic [4, 5] <strong>and</strong> category<br />

theory [14]. In [1], another formalism is presented which is<br />

<strong>of</strong> particular interest in the context <strong>of</strong> <strong>Scheme</strong>. It relies on a<br />

predicative logic system, which corresponds to certain dynamic<br />

run-time checks that can exclude formation <strong>of</strong> exotic terms.<br />

This formalism is extended in [12].<br />

Induction: another common problem is that the representation<br />

contains functions (which puts a function type in a negative position),<br />

<strong>and</strong> therefore does not easily lend itself to induction.<br />

Several solutions for this problem exist. As previously demonstrated<br />

[1], these functions behave in a way that makes them<br />

directly correspond to concrete syntax. In <strong>Scheme</strong>, the quotation<br />

macro can add the missing information — add the syntactic<br />

information that contains enough hints to recover the structure<br />

(but see [1] for why this is not straightforward).<br />

As a side note, it is clear that using HOAS is very different in<br />

its nature than using high-level <strong>Scheme</strong> macros. Instead <strong>of</strong> plain<br />

pattern matching <strong>and</strong> template filling, we need to know <strong>and</strong> encode<br />

the exact lexical structure <strong>of</strong> any binding form that we wish to<br />

encode. Clearly, the code that is presented here is simplified as<br />

it has just one binding form, but we would face such problems if<br />

we would represent more binding constructs like let, let* <strong>and</strong><br />

letrec. This is not necessarily a negative feature, since lexical<br />

scope needs to be specified in any case.<br />

9. Conclusion<br />

We have presented code that uses HOAS techniques in <strong>Scheme</strong>.<br />

The technique is powerful enough to make it possible to write a<br />

small evaluator that can evaluate itself, <strong>and</strong> — as we have shown<br />

— be powerful enough to model different evaluation approaches.<br />

In addition to being robust, the encoding is efficient enough to be<br />

practical even at three levels <strong>of</strong> nested evaluators, or when using<br />

lazy semantics. HOAS is therefore a useful tool in the <strong>Scheme</strong><br />

world in addition to the usual host <strong>of</strong> meta-level syntactic tools.<br />

We plan on further work in this area, specifically, it is possible<br />

that using a HOAS representation for PLT’s Reduction Semantics<br />

[11] tool will result in a speed boost, <strong>and</strong> a cleaner solution to its<br />

custom substitution specification language. Given that we’re using<br />

<strong>Scheme</strong> bindings to represent bindings may make it possible to<br />

use HOAS-based techniques combined with <strong>Scheme</strong> macros. For<br />

example, we can represent a language in <strong>Scheme</strong> using <strong>Scheme</strong><br />

binders, allowing it to be extended via <strong>Scheme</strong> macros in a way<br />

that still respects <strong>Scheme</strong>’s lexical scope rules.<br />

References<br />

[1] Eli Barzilay. Implementing Direct Reflection in Nuprl. PhD thesis,<br />

Cornell <strong>University</strong>, Ithaca, NY, January <strong>2006</strong>.<br />

[2] Eli Barzilay <strong>and</strong> Stuart Allen. Reflecting higher-order abstract<br />

syntax in Nuprl. In Victor A. Carreño, Cézar A. Muñoz, <strong>and</strong><br />

Sophiène Tahar, editors, Theorem Proving in Higher Order Logics;<br />

Track B Proceedings <strong>of</strong> the 15th International Conference on<br />

Theorem Proving in Higher Order Logics (TPHOLs 2002), Hampton,<br />

VA, August 2002, pages 23–32. National Aeronautics <strong>and</strong> Space<br />

Administration, 2002.<br />

[3] R. L. Constable, S. F. Allen, H. M. Bromley, W. R. Cleavel<strong>and</strong>,<br />

J. F. Cremer, R. W. Harper, D. J. Howe, T. B. Knoblock, N. P.<br />

Mendler, P. Panangaden, J. T. Sasaki, <strong>and</strong> S. F. Smith. Implementing<br />

Mathematics with the Nuprl Pro<strong>of</strong> Development System. Prentice-<br />

Hall, NJ, 1986.<br />

[4] Rowan Davies <strong>and</strong> Frank Pfenning. A modal analysis <strong>of</strong> staged<br />

computation. In Conf. Record 23rd ACM SIGPLAN/SIGACT Symp.<br />

on Principles <strong>of</strong> <strong>Programming</strong> Languages, POPL’96, pages 258–270.<br />

ACM Press, New York, 1996.<br />

[5] Joëlle Despeyroux <strong>and</strong> Pierre Leleu. A modal lambda-calculus with<br />

iteration <strong>and</strong> case constructs. In Proc. <strong>of</strong> the annual Types seminar,<br />

March 1999.<br />

[6] Robert Bruce Findler. PLT Dr<strong>Scheme</strong>: <strong>Programming</strong> environment<br />

manual. Technical Report PLT-TR<strong>2006</strong>-3-v352, PLT <strong>Scheme</strong> Inc.,<br />

<strong>2006</strong>. See also: Findler, R. B., J. Clements, C. Flanagan, M. Flatt, S.<br />

Krishnamurthi, P. Steckler <strong>and</strong> M. Felleisen. Dr<strong>Scheme</strong>: A programming<br />

environment for <strong>Scheme</strong>, Journal <strong>of</strong> <strong>Functional</strong> <strong>Programming</strong>,<br />

12(2):159–182, March 2002. http://www.ccs.neu.edu/scheme/pubs/.<br />

[7] Matthew Flatt. PLT Mz<strong>Scheme</strong>: Language manual. Technical<br />

Report PLT-TR<strong>2006</strong>-1-v352, PLT <strong>Scheme</strong> Inc., <strong>2006</strong>. http:<br />

//www.plt-scheme.org/techreports/.<br />

[8] Erik Hilsdale <strong>and</strong> Daniel P. Friedman. Writing macros in<br />

continuation-passing style. In <strong>Scheme</strong> <strong>and</strong> <strong>Functional</strong> <strong>Programming</strong><br />

2000, page 53, September 2000.<br />

[9] Martin H<strong>of</strong>mann. Semantical analysis <strong>of</strong> higher-order abstract syntax.<br />

In 14th Symposium on Logic in Computer Science, page 204. LICS,<br />

July 1999.<br />

[10] Oleg Kiselyov. Macros that compose: Systematic macro programming.<br />

In Generative <strong>Programming</strong> <strong>and</strong> Component Engineering<br />

(GPCE’02), 2002.<br />

[11] Jacob Matthews, Robert Bruce Findler, Matthew Flatt, <strong>and</strong> Matthias<br />

Felleisen. A visual environment for developing context-sensitive<br />

term rewriting systems. In International Conference on Rewriting<br />

Techniques <strong>and</strong> Applications, 2004.<br />

[12] Aleksey Nogin, Alexei Kopylov, Xin Yu, <strong>and</strong> Jason Hickey. A<br />

computational approach to reflective meta-reasoning about languages<br />

with bindings. In MERLIN ’05: Proceedings <strong>of</strong> the 3rd ACM<br />

SIGPLAN workshop on Mechanized reasoning about languages with<br />

variable binding, pages 2–12, Tallinn, Estonia, September 2005.<br />

ACM Press.<br />

[13] Frank Pfenning <strong>and</strong> Conal Elliott. Higher-order abstract syntax. In<br />

Proceedings <strong>of</strong> the ACM SIGPLAN ’88 Conference on <strong>Programming</strong><br />

Language Design <strong>and</strong> Implementation (PLDI), pages 199–208,<br />

Atlanta, Georgia, June 1988. ACM Press.<br />

[14] Carsten Schürmann. Recursion for higher-order encodings. In<br />

Proceedings <strong>of</strong> Computer Science Logic (CSL 2001), pages 585–599,<br />

2001.<br />

[15] M. R. Shinwell, A. M. Pitts, <strong>and</strong> M. J. Gabbay. FreshML:<br />

<strong>Programming</strong> with binders made simple. In Eighth ACM SIGPLAN<br />

International Conference on <strong>Functional</strong> <strong>Programming</strong> (ICFP 2003),<br />

Uppsala, Sweden, pages 263–274. ACM Press, August 2003.<br />

[16] C. Urban, A. M. Pitts, <strong>and</strong> M. J. Gabbay. Nominal unification.<br />

In M. Baaz, editor, Computer Science Logic <strong>and</strong> 8th Kurt Gödel<br />

Colloquium (CSL’03 & KGC), Vienna, Austria. Proccedings, Lecture<br />

Notes in Computer Science, pages 513–527. Springer-Verlag, Berlin,<br />

2003.<br />

[17] Christian Urban <strong>and</strong> Christine Tasson. Nominal reasoning techniques<br />

in isabelle/hol. In Proceedings <strong>of</strong> the 20th Conference on Automated<br />

Deduction (CADE 2005), volume 3632, pages 38–53, Tallinn,<br />

Estonia, July 2005. Springer Verlag.<br />

124 <strong>Scheme</strong> <strong>and</strong> <strong>Functional</strong> <strong>Programming</strong>, <strong>2006</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!