Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
OCaml
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===MetaOCaml=== MetaOCaml<ref name = "Meta">{{cite web|url=http://okmij.org/ftp/ML/MetaOCaml.html|title=BER MetaOCaml|last=oleg-at-okmij.org|website=okmij.org}}</ref> is a [[multi-stage programming]] extension of OCaml enabling incremental compiling of new [[machine code]] during runtime. Under some circumstances, significant [[Speedup|speedups]] are possible using [[Multi-stage programming|multistage programming]], because more detailed information about the data to process is available at runtime than at the regular compile time, so the incremental compiler can optimize away many cases of condition checking, etc. As an example: if at compile time it is known that some [[Exponentiation|power function]] {{OCaml|x -> x^n}} is needed often, but the value of {{OCaml|n}} is known only at [[Runtime system|runtime]], a two-stage power function can be used in MetaOCaml: <syntaxhighlight lang="OCaml"> let rec power n x = if n = 0 then .<1>. else if even n then sqr (power (n/2) x) else .<.~x *. .~(power (n - 1) x)>. </syntaxhighlight> As soon as {{OCaml|n}} is known at runtime, a specialized and very fast power function can be created: <syntaxhighlight lang="OCaml"> .<fun x -> .~(power 5 .<x>.)>. </syntaxhighlight> The result is: <syntaxhighlight lang="OCaml"> fun x_1 -> (x_1 * let y_3 = let y_2 = (x_1 * 1) in (y_2 * y_2) in (y_3 * y_3)) </syntaxhighlight> The new function is automatically compiled.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
OCaml
(section)
Add topic