DOC PREVIEW
UA CSC 520 - Study Notes

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

O’Caml by Pavan Krishnamurthy and Qiyam TungTable of Contents Introduction......................................................................................................................... 3 History of ML/OCaml......................................................................................................... 3 Audience ............................................................................................................................. 3 Types................................................................................................................................... 3 • Type Inference ........................................................................................................ 3 • Simple Types .......................................................................................................... 4 Labels.................................................................................................................................. 4 Variants............................................................................................................................... 5 • Recursive variants (trees)........................................................................................ 5 • Parameterized variants............................................................................................ 5 Aliases (Currying)............................................................................................................... 6 Pattern Matching................................................................................................................. 6 Object Oriented Features .................................................................................................... 7 • Classes & Objects ................................................................................................... 7 • Immediate Objects .................................................................................................. 7 • Functional Objects .................................................................................................. 7 • Cloning Objects ...................................................................................................... 8 Inheritance........................................................................................................................... 8 Coercions ............................................................................................................................ 8 Parametric Polymorphism................................................................................................... 9 Exception Handling .......................................................................................................... 10 Garbage Collector............................................................................................................. 10 OCaml Intrepreter............................................................................................................. 11Introduction OCaml is the most popular variant of the ML branch Caml (Categorical Abstract Machine Language). It is a functional programming language with an added advantage of type inference and static typing, which means that most types are safe and there are very less chances of run time failures in OCaml. So it is considered a safe language. There are lot of intresting features in OCaml which attracts users and makes it an efficient functional language. History of ML/OCaml ML was designed by Robin Milner to allow programmers to develop theorem proving techniques. A series of events led to the development of Caml, which was based on a branch of mathematics developed by Pierre-Louis Curien that allowed for the techniques to be proven in a simple way. In the 90’s, object-oriented programming and type systems were a hot research area. The hype led to the development of OCaml, which is object-oriented but elegantly done, unlike the patched C++. According to the website, OCaml “was the first language (and still is the only language) that combines the full power of object-oriented programming with ML-style static typing and type inference.” Audience While OCaml is an impure functional programming language, it distinguishes itself from most other functional languages by being fast. Based on benchmarks, on average, OCaml performs at least 50% the speed of equivalent C programs, which is fairly good. One of the reasons for this performance is that it was built to be fast from the beginning; furthermore, it supports imperative features in cases where functional programming cannot provide the speed necessary for the application. A distinct feature of OCaml and of the ML programming languages is their use of static types and type inference. This combination allows the compiler to prevent programming errors one usually encounters in Java and C/C++. That is, it guarantees runtime safety without runtime checks (except for cases such as array bounds checking). It is an attractive programming language in that it is has the elegance and readability of functional languages, acceptable execution time, as well as the ability to write large programs thanks to its object-oriented features. It is more tailored towards more numerical programming and in creating programs the assist in proofs. For example, Coq Proof Assistant, as its name implies, helps to verify mathematical proofs. The following are features of OCaml are: Types • Type Inference OCaml is a static-typed language. This means it picks up the type mismatch at the compile time. This makes the interpreter work easier when executing it. Static typing also makes the programs safer , since everything is checked at compile time they are proven to run safe. A dynamically typed language has the advantage of not needing to define its type during compile-time, but potential type errors could occur during runtime. Along with static typing OCaml is also type inferred language which means the user need not specify what type of variable it is , it’s the compiler job to detect it. For example. let multiply2 x = x * 2;; Since 2 is multiplied with x , compiler infers that x has to be a number and it later verifies by the operator specified. Because of the potential ambiguity that arises from floatingpoint and integers, *. is used to denote floating point multiplication. Hence if instead of 2 it is 2.0


View Full Document

UA CSC 520 - Study Notes

Documents in this Course
Handout

Handout

13 pages

Semantics

Semantics

15 pages

Haskell

Haskell

15 pages

Recursion

Recursion

18 pages

Semantics

Semantics

12 pages

Scheme

Scheme

32 pages

Syllabus

Syllabus

40 pages

Haskell

Haskell

17 pages

Scheme

Scheme

27 pages

Scheme

Scheme

9 pages

TypeS

TypeS

13 pages

Scheme

Scheme

27 pages

Syllabus

Syllabus

10 pages

Types

Types

16 pages

FORTRAN

FORTRAN

10 pages

Load more
Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?