Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Homoiconic type theory

Lisp has the property of being homoiconic, that is, the representation of code used by the language implementation (lists) is also available to, and idiomatically used by, programs that want to represent code for their own purposes.

The other major family of functional programming languages, ML, is based on type theory, which means that the language implementation needs a more complex representation of code, and is also less casual about what you are allowed to do, so typically the internal representation is not available to programs. For example, proof checkers for higher-order logic are often implemented in ML family languages, but normally implement their own type theory system, effectively ignoring the fact that the ML compiler has one already.

Are there any exceptions to this? Any programming languages based on type theory, that expose their code representation for programmatic use?

like image 481
rwallace Avatar asked Nov 29 '11 01:11

rwallace


2 Answers

Take a look at type systems for staged execution (a weak form of metaprogramming), for example, the one used in MetaML language.

Also note that while attractive at first glance, homoiconicity (and metaprogramming by direct AST manipulation in general) turned out to be inconvenient in practice. Take a look at modern systems of macros in Nemerle and an experimental extension of Scala, which both rely on quasi-quotation if I remember correctly.

As for why ML type theory is not reused, here are a few considerations:

  • ML type system is not expressive enough (think of dependent types)
  • ML type system is polluted with general recursion and mutable references
  • There are no consensus on which type system is usable both for proving and writing general-purpose programs. It is an ongoing research. See for example http://www.nii.ac.jp/shonan/seminar007/ . So every prover implements his own theory just because authors fix flaws in previous type theories.
like image 50
nponeccop Avatar answered Oct 07 '22 17:10

nponeccop


The other major family of functional programming languages ... is based on type theory, which means that the language implementation needs a more complex representation of code

I see no reason why this would be true.

If you haven't seen it already, you may be interested in Liskell, which advertises itself as Haskell semantics + Lisp syntax.

like image 21
Matt Fenwick Avatar answered Oct 07 '22 17:10

Matt Fenwick