Penguin
Note: You are viewing an old revision of this page. View the current version.

ML is a family of StaticallyTyped FunctionalLanguage?s with StrictEvaluation, PolymorpicTypes?, HigherOrderFunctions, a higher-order module system. ML can be used interactively for learning, experimentation and testing, or it can be compiled. The two major dialects of ML are Ocaml? and SML. SML is a standardised language with several implementations. Ocaml has a single open source implementation, it extends ML with an OOP system. Both major dialects have compilers that produce native code that rivals the speed of C++, and extensive standard and third-party libraries.

Why YOU want to program in ML gives you a tour of the features of ML that make it a good general-purpose programming language. It talks about SML, but what it says applies to Ocaml? as well.

!!!An example of ML code

fun interpret_functionally (program : opcode list) : unit =

(* Interprets a parsed Brainf*ck program using integers

on a strip of TuringMachine tape as the memory. *)

let

val fresh_tape = Tape.make(0) fun step (tape, op) =

let byte = Tape.read(tape) in

case op of

Inc_ptr n => times(n, Tape.forward, tape)

| Dec_ptr n => times(n, Tape.back, tape) | Inc_byte n => Tape.write(byte + n, tape) | Dec_byte n => Tape.write(byte - n, tape) | Putchar => ( putchar(byte) ; tape ) | Getchar => Tape.write(getchar(), tape) | Loop body =>

if byte = 0 then tape else step (step_sequence (tape, body), op)

end

fun step_sequence (tape, oplist) =

List.foldl(step, tape, oplist)

in

ignore (step_sequence(fresh_tape, program))

end

(This is in SML.)