Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Functional programming languages introspection

I'm sketching a design of something (machine learning of functions) that will preferably want a functional programming language, and also introspection, specifically the ability to examine the program's own code in some nicely tractable format, and preferably also the ability to get machine generated code compiled at runtime, and I'm wondering what's the best language to write it in. Lisp of course has strong introspection capabilities, but the statically typed languages also have advantages; the ones I'm considering are:

F# - the .Net platform has a good story here, you can read byte code at run time and also emit byte code and get it compiled; I assume there's no problem accessing these facilities from F#.

Haskell, Ocaml - do these have similar facilities, either via byte code or parse tree?

Are there other languages I should also be looking at?

like image 904
rwallace Avatar asked Sep 07 '10 17:09

rwallace


People also ask

What is introspection in programming language?

In computing, type introspection is the ability of a program to examine the type or properties of an object at runtime. Some programming languages possess this capability.

What languages support reflection?

Programming languages and platforms that typically support reflection include dynamically typed languages such as Smalltalk, Perl, PHP, Python, VBScript, and JavaScript. Also the . NET Languages are supported and the Maude system of rewriting logic.

What are the types of introspection?

Psychologists differentiate between two types of introspection: self-reflection and self-rumination.


2 Answers

Haskell's introspection mechanism is Template Haskell, which supports compile time metaprogramming, and when combined with e.g. llvm, provides runtime metaprogramming facilities.

like image 154
Don Stewart Avatar answered Sep 19 '22 15:09

Don Stewart


Ocaml has:

  • Camlp4 to manipulate Ocaml concrete syntax trees in Ocaml. The maintained implementation of Camlp4 is Camlp5.

  • MetaOCaml for full-scale multi-stage programming.

  • Ocamljit to generate native code at run time, but I don't think it's been maintained recently.

  • Ocaml-Java to compile Ocaml code for the Java virtual machine. I don't know if there are nice reflection capabilities.

like image 28
Gilles 'SO- stop being evil' Avatar answered Sep 17 '22 15:09

Gilles 'SO- stop being evil'