Hello World (OCaml/F Sharp)

From LiteratePrograms

(Redirected from Hello World (OCaml))
Jump to: navigation, search
Other implementations: Ada | ALGOL 68 | Alice ML | Amiga E | Applescript | AspectJ | Assembly Intel x86 Linux | Assembly Intel x86 NetBSD | AWK | bash | BASIC | Batch files | C | C, Cairo | C, Xlib | Candle | Clojure | C++ | C# | Delphi | Dylan | E | Eiffel | Erlang | Forth | FORTRAN | Fortress | Go | Groovy | Haskell | Hume | IBM PC bootstrap | Inform 7 | Java | Java, Swing | JavaScript | LaTeX | Lisp | Logo | Lua | Maple | MATLAB | Mercury | OCaml/F Sharp | occam | Oz | Pascal | Perl | PHP | Pic | PIR | PLI | PostScript | Prolog | Python | Rexx | Ruby | Scala | Scheme | Seed7 | sh | Smalltalk | SQL | Standard ML | SVG | Tcl | Tcl Tk | Visual Basic | Visual Basic .NET | XSL

Hello World in Ocaml and F# (the program is identical for each). The "let () =" ensures that the return value of the following expression is "()" (the only value of type unit). This detects e.g. missing arguments (it is unecessary for such a simple program but better start with good habits!).

<<hello.ml>>=
let () = print_endline "Hello World!"

This no longer works in F# 2.0 (and possibly earlier versions). Now you would use:

<<hello.ml>>=
let () = printfn "Hello World!";;
Download code
Views
Personal tools