Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/mllike
File: index.html
<!doctype html>
[0] Fix | Delete
[1] Fix | Delete
<title>CodeMirror: ML-like mode</title>
[2] Fix | Delete
<meta charset="utf-8"/>
[3] Fix | Delete
<link rel=stylesheet href="../../doc/docs.css">
[4] Fix | Delete
[5] Fix | Delete
<link rel=stylesheet href=../../lib/codemirror.css>
[6] Fix | Delete
<script src=../../lib/codemirror.js></script>
[7] Fix | Delete
<script src=../../addon/edit/matchbrackets.js></script>
[8] Fix | Delete
<script src=mllike.js></script>
[9] Fix | Delete
<style type=text/css>
[10] Fix | Delete
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
[11] Fix | Delete
</style>
[12] Fix | Delete
<div id=nav>
[13] Fix | Delete
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
[14] Fix | Delete
[15] Fix | Delete
<ul>
[16] Fix | Delete
<li><a href="../../index.html">Home</a>
[17] Fix | Delete
<li><a href="../../doc/manual.html">Manual</a>
[18] Fix | Delete
<li><a href="https://github.com/codemirror/codemirror">Code</a>
[19] Fix | Delete
</ul>
[20] Fix | Delete
<ul>
[21] Fix | Delete
<li><a href="../index.html">Language modes</a>
[22] Fix | Delete
<li><a class=active href="#">ML-like</a>
[23] Fix | Delete
</ul>
[24] Fix | Delete
</div>
[25] Fix | Delete
[26] Fix | Delete
<article>
[27] Fix | Delete
<h2>OCaml mode</h2>
[28] Fix | Delete
[29] Fix | Delete
[30] Fix | Delete
<textarea id="ocamlCode">
[31] Fix | Delete
(* Summing a list of integers *)
[32] Fix | Delete
let rec sum xs =
[33] Fix | Delete
match xs with
[34] Fix | Delete
| [] -&gt; 0
[35] Fix | Delete
| x :: xs' -&gt; x + sum xs'
[36] Fix | Delete
[37] Fix | Delete
(* Quicksort *)
[38] Fix | Delete
let rec qsort = function
[39] Fix | Delete
| [] -&gt; []
[40] Fix | Delete
| pivot :: rest -&gt;
[41] Fix | Delete
let is_less x = x &lt; pivot in
[42] Fix | Delete
let left, right = List.partition is_less rest in
[43] Fix | Delete
qsort left @ [pivot] @ qsort right
[44] Fix | Delete
[45] Fix | Delete
(* Fibonacci Sequence *)
[46] Fix | Delete
let rec fib_aux n a b =
[47] Fix | Delete
match n with
[48] Fix | Delete
| 0 -&gt; a
[49] Fix | Delete
| _ -&gt; fib_aux (n - 1) (a + b) a
[50] Fix | Delete
let fib n = fib_aux n 0 1
[51] Fix | Delete
[52] Fix | Delete
(* Birthday paradox *)
[53] Fix | Delete
let year_size = 365.
[54] Fix | Delete
[55] Fix | Delete
let rec birthday_paradox prob people =
[56] Fix | Delete
let prob' = (year_size -. float people) /. year_size *. prob in
[57] Fix | Delete
if prob' &lt; 0.5 then
[58] Fix | Delete
Printf.printf "answer = %d\n" (people+1)
[59] Fix | Delete
else
[60] Fix | Delete
birthday_paradox prob' (people+1) ;;
[61] Fix | Delete
[62] Fix | Delete
birthday_paradox 1.0 1
[63] Fix | Delete
[64] Fix | Delete
(* Church numerals *)
[65] Fix | Delete
let zero f x = x
[66] Fix | Delete
let succ n f x = f (n f x)
[67] Fix | Delete
let one = succ zero
[68] Fix | Delete
let two = succ (succ zero)
[69] Fix | Delete
let add n1 n2 f x = n1 f (n2 f x)
[70] Fix | Delete
let to_string n = n (fun k -&gt; "S" ^ k) "0"
[71] Fix | Delete
let _ = to_string (add (succ two) two)
[72] Fix | Delete
[73] Fix | Delete
(* Elementary functions *)
[74] Fix | Delete
let square x = x * x;;
[75] Fix | Delete
let rec fact x =
[76] Fix | Delete
if x &lt;= 1 then 1 else x * fact (x - 1);;
[77] Fix | Delete
[78] Fix | Delete
(* Automatic memory management *)
[79] Fix | Delete
let l = 1 :: 2 :: 3 :: [];;
[80] Fix | Delete
[1; 2; 3];;
[81] Fix | Delete
5 :: l;;
[82] Fix | Delete
[83] Fix | Delete
(* Polymorphism: sorting lists *)
[84] Fix | Delete
let rec sort = function
[85] Fix | Delete
| [] -&gt; []
[86] Fix | Delete
| x :: l -&gt; insert x (sort l)
[87] Fix | Delete
[88] Fix | Delete
and insert elem = function
[89] Fix | Delete
| [] -&gt; [elem]
[90] Fix | Delete
| x :: l -&gt;
[91] Fix | Delete
if elem &lt; x then elem :: x :: l else x :: insert elem l;;
[92] Fix | Delete
[93] Fix | Delete
(* Imperative features *)
[94] Fix | Delete
let add_polynom p1 p2 =
[95] Fix | Delete
let n1 = Array.length p1
[96] Fix | Delete
and n2 = Array.length p2 in
[97] Fix | Delete
let result = Array.create (max n1 n2) 0 in
[98] Fix | Delete
for i = 0 to n1 - 1 do result.(i) &lt;- p1.(i) done;
[99] Fix | Delete
for i = 0 to n2 - 1 do result.(i) &lt;- result.(i) + p2.(i) done;
[100] Fix | Delete
result;;
[101] Fix | Delete
add_polynom [| 1; 2 |] [| 1; 2; 3 |];;
[102] Fix | Delete
[103] Fix | Delete
(* We may redefine fact using a reference cell and a for loop *)
[104] Fix | Delete
let fact n =
[105] Fix | Delete
let result = ref 1 in
[106] Fix | Delete
for i = 2 to n do
[107] Fix | Delete
result := i * !result
[108] Fix | Delete
done;
[109] Fix | Delete
!result;;
[110] Fix | Delete
fact 5;;
[111] Fix | Delete
[112] Fix | Delete
(* Triangle (graphics) *)
[113] Fix | Delete
let () =
[114] Fix | Delete
ignore( Glut.init Sys.argv );
[115] Fix | Delete
Glut.initDisplayMode ~double_buffer:true ();
[116] Fix | Delete
ignore (Glut.createWindow ~title:"OpenGL Demo");
[117] Fix | Delete
let angle t = 10. *. t *. t in
[118] Fix | Delete
let render () =
[119] Fix | Delete
GlClear.clear [ `color ];
[120] Fix | Delete
GlMat.load_identity ();
[121] Fix | Delete
GlMat.rotate ~angle: (angle (Sys.time ())) ~z:1. ();
[122] Fix | Delete
GlDraw.begins `triangles;
[123] Fix | Delete
List.iter GlDraw.vertex2 [-1., -1.; 0., 1.; 1., -1.];
[124] Fix | Delete
GlDraw.ends ();
[125] Fix | Delete
Glut.swapBuffers () in
[126] Fix | Delete
GlMat.mode `modelview;
[127] Fix | Delete
Glut.displayFunc ~cb:render;
[128] Fix | Delete
Glut.idleFunc ~cb:(Some Glut.postRedisplay);
[129] Fix | Delete
Glut.mainLoop ()
[130] Fix | Delete
[131] Fix | Delete
(* A Hundred Lines of Caml - http://caml.inria.fr/about/taste.en.html *)
[132] Fix | Delete
(* OCaml page on Wikipedia - http://en.wikipedia.org/wiki/OCaml *)
[133] Fix | Delete
</textarea>
[134] Fix | Delete
[135] Fix | Delete
<h2>F# mode</h2>
[136] Fix | Delete
<textarea id="fsharpCode">
[137] Fix | Delete
module CodeMirror.FSharp
[138] Fix | Delete
[139] Fix | Delete
let rec fib = function
[140] Fix | Delete
| 0 -> 0
[141] Fix | Delete
| 1 -> 1
[142] Fix | Delete
| n -> fib (n - 1) + fib (n - 2)
[143] Fix | Delete
[144] Fix | Delete
type Point =
[145] Fix | Delete
{
[146] Fix | Delete
x : int
[147] Fix | Delete
y : int
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
type Color =
[151] Fix | Delete
| Red
[152] Fix | Delete
| Green
[153] Fix | Delete
| Blue
[154] Fix | Delete
[155] Fix | Delete
[0 .. 10]
[156] Fix | Delete
|> List.map ((+) 2)
[157] Fix | Delete
|> List.fold (fun x y -> x + y) 0
[158] Fix | Delete
|> printf "%i"
[159] Fix | Delete
</textarea>
[160] Fix | Delete
[161] Fix | Delete
[162] Fix | Delete
<script>
[163] Fix | Delete
var ocamlEditor = CodeMirror.fromTextArea(document.getElementById('ocamlCode'), {
[164] Fix | Delete
mode: 'text/x-ocaml',
[165] Fix | Delete
lineNumbers: true,
[166] Fix | Delete
matchBrackets: true
[167] Fix | Delete
});
[168] Fix | Delete
[169] Fix | Delete
var fsharpEditor = CodeMirror.fromTextArea(document.getElementById('fsharpCode'), {
[170] Fix | Delete
mode: 'text/x-fsharp',
[171] Fix | Delete
lineNumbers: true,
[172] Fix | Delete
matchBrackets: true
[173] Fix | Delete
});
[174] Fix | Delete
</script>
[175] Fix | Delete
[176] Fix | Delete
<p><strong>MIME types defined:</strong> <code>text/x-ocaml</code> (OCaml) and <code>text/x-fsharp</code> (F#).</p>
[177] Fix | Delete
</article>
[178] Fix | Delete
[179] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function