Caml

Caml
ParadigmMulti-paradigm: functional, imperative
FamilyML
Designed byGérard Huet, Guy Cousineau, Ascánder Suárez, Pierre Weis, Michel Mauny (Heavy Caml), Xavier Leroy (Caml Light)
DeveloperINRIA, ENS
First appeared1985; 40 years ago (1985)
Stable release
0.75[1] / January 26, 2002; 22 years ago (2002-01-26)
Typing disciplineinferred, static, strong
Memory managementautomatic
OSCross-platform: Unix, Linux, macOS; Windows
LicenseQPL 1, LGPL 2 (Caml Light)
Websitecaml.inria.fr
Influenced by
ML
Influenced
OCaml

Caml (originally an acronym for Categorical Abstract Machine Language) is a multi-paradigm, general-purpose, high-level, functional programming language which is a dialect of the ML programming language family. Caml was developed in France at French Institute for Research in Computer Science and Automation (INRIA) and École normale supérieure (Paris) (ENS).

Caml is statically typed, strictly evaluated, and uses automatic memory management. OCaml, the main descendant of Caml, adds many features to the language, including an object-oriented programming (object) layer.

Examples

In the following, # represents the Caml prompt.

Hello World

A "Hello, World!" program is:

print_endline "Hello, world!";;

Factorial function (recursion and purely functional programming)

Many mathematical functions, such as factorial, are most naturally represented in a purely functional form. The following recursive, purely functional Caml function implements factorial:

let rec fact n = if n=0 then 1 else n * fact(n - 1);;

The function can be written equivalently using pattern matching:

let rec fact = function
  | 0 -> 1
  | n -> n * fact(n - 1);;

This latter form is the mathematical definition of factorial as a recurrence relation.

Note that the compiler inferred the type of this function to be int -> int, meaning that this function maps ints onto ints. For example, 12! is:

 # fact 12;;
 - : int = 479001600

Numerical derivative (higher-order functions)

Since Caml is a functional programming language, it is easy to create and pass around functions in Caml programs. This ability has very many applications. Calculating the numerical derivative of a function is one example. The following Caml function d computes the numerical derivative of a given function f at a given point x:

let d delta f x =
  (f (x +. delta) -. f (x -. delta)) /. (2. *. delta);;

This function requires a small value delta. A good choice for delta is the cube root of the machine epsilon.[citation needed].

The type of the function d indicates that it maps a float onto another function with the type (float -> float) -> float -> float. This allows us to partially apply arguments. This functional style is known as currying. In this case, it is useful to partially apply the first argument delta to d, to obtain a more specialised function:

# let d = d (sqrt epsilon_float);;
val d : (float -> float) -> float -> float = <fun>

Note that the inferred type indicates that the replacement d is expecting a function with the type float -> float as its first argument. We can compute a numerical approximation to the derivative of at with:

# d (fun x -> x *. x *. x -. x -. 1.) 3.;;
- : float = 26.

The correct answer is .

The function d is called a "higher-order function" because it accepts another function (f) as an argument. Going further can create the (approximate) derivative of f, by applying d while omitting the x argument:

# let f' = d (fun x -> x *. x *. x -. x -. 1.) ;;
val f' : float -> float = <fun>

The concepts of curried and higher-order functions are clearly useful in mathematical programs. These concepts are equally applicable to most other forms of programming and can be used to factor code much more aggressively, resulting in shorter programs and fewer bugs.

Discrete wavelet transform (pattern matching)

The 1D Haar wavelet transform of an integer-power-of-two-length list of numbers can be implemented very succinctly in Caml and is an excellent example of the use of pattern matching over lists, taking pairs of elements (h1 and h2) off the front and storing their sums and differences on the lists s and d, respectively:

# let haar l =
   let rec aux l s d = 
     match l, s, d with
       [s], [], d -> s :: d
     | [], s, d -> aux s [] d
     | h1 :: h2 :: t, s, d -> aux t (h1 + h2 :: s) (h1 - h2 :: d)
     | _ -> invalid_arg "haar" 
     in aux l [] [];;
val haar : int list -> int list = <fun>

For example:

  # haar [1; 2; 3; 4; -4; -3; -2; -1];;
   - : int list = [0; 20; 4; 4; -1; -1; -1; -1]

Pattern matching allows complicated transformations to be represented clearly and succinctly. Moreover, the Caml compiler turns pattern matches into very efficient code, at times resulting in programs that are shorter and faster than equivalent code written with a case statement (Cardelli 1984, p. 210.).

History

The first Caml implementation was written in Lisp by Ascánder Suárez in 1987 at the French Institute for Research in Computer Science and Automation (INRIA).[2]

Its successor, Caml Light, was implemented in C by Xavier Leroy and Damien Doligez,[2] and the original was nicknamed "Heavy Caml" because of its higher memory and CPU requirements.[2]

Caml Special Light was a further complete rewrite that added a powerful module system to the core language. It was augmented with an object-oriented programming (object) layer to become Objective Caml, eventually renamed OCaml.

See also

References

  1. ^ "Latest Caml Light release". Retrieved 22 February 2020.
  2. ^ a b c "A History of Caml", inria.fr

Bibliography

Read other articles:

Giorgio AgambenLukisan dinding Agamben di Abode of Chaos, PrancisLahir22 April 1942 (umur 81)Roma, ItaliaAlmamaterUniversitas Sapienza Roma (Laurea, 1965)EraFilsafat kontemporerKawasanFilsafat baratAliranFilsafat kontinentalPascamarxismeFilsafat hidup[1]Minat utamaEstetikaFilsafat politikGagasan pentingHomo sacerState of ExceptionForm-of-life Dipengaruhi Aristotle · Marx · Debord · Foucault · Benjamin · Derrida ·&...

 

 

Sedanauibukota kecamatanKelurahanNegara IndonesiaProvinsiKepulauan RiauKabupatenNatunaKecamatanBunguran BaratKode Kemendagri21.03.05.1008 Kode BPS2103040008 Luas20,58 km²Jumlah penduduk5.964 jiwa (2017)Kepadatan290 jiwa/km² (2017) Sedanau merupakan kelurahan sekaligus ibu kota Kecamatan Bunguran Barat, Kabupaten Natuna, Kepulauan Riau, Indonesia. Sedanau merupakan wilayah terpadat dan terbanyak penduduknya di Kecamatan Bunguran Barat. Secara geografis terletak di daerah pantai dengan t...

 

 

Henry Agard WallaceHenry Wallace Wakil Presiden Amerika Serikat 33Masa jabatan20 Januari 1941 – 20 Januari 1945 PendahuluJohn GarnerPenggantiHarry S. Truman Informasi pribadiPartai politikDemokratSuami/istriIlo WallacePekerjaanPolitikusSunting kotak info • L • B Henry Wallace beralih ke halaman ini. Untuk kegunaan lain, lihat Henry Wallace (disambiguasi). Henry Agard Wallace lahir di tanah pertanian Orient, Adair County, Iowa pada tanggal 7 Oktober 1888. Henry mel...

Departemen KehakimanInformasi DepartemenDibentuk22 Juni 1870; 153 tahun lalu (1870-06-22)1 Juli 1870; 153 tahun lalu (1870-07-01)Wilayah hukumPemerintah federal Amerika SerikatKantor pusatRobert F. Kennedy Department of Justice Building950 Pennsylvania Avenue NWWashington, D.C.38°53′35.7″N 77°1′29.9″W / 38.893250°N 77.024972°W / 38.893250; -77.024972Koordinat: 38°53′35.7″N 77°1′29.9″W / 38.893250°N 77.024972°W /...

 

 

Sniper rifle Dan IWI Dan at IDEX 2023TypeSniper riflePlace of origin IsraelProduction historyDesignerNehemia SirkisManufacturerIsrael Weapon IndustriesProduced2014–presentSpecificationsMass5.9 kg (13.01 lb) 7.3 kg (16 lb) folding stock versionLength1,280 mm (50.4 in) 1,030 mm (40.6 in) stock foldedBarrel length737 mm (29.0 in)Cartridge.338 Lapua MagnumActionBolt-actionMuzzle velocity881 m/s (2,890 ft/s)Effe...

 

 

Pour les articles homonymes, voir Générateur. Si ce bandeau n'est plus pertinent, retirez-le. Cliquez ici pour en savoir plus. Cet article ne cite pas suffisamment ses sources (décembre 2014). Si vous disposez d'ouvrages ou d'articles de référence ou si vous connaissez des sites web de qualité traitant du thème abordé ici, merci de compléter l'article en donnant les références utiles à sa vérifiabilité et en les liant à la section « Notes et références ». En prat...

Compianto sul Cristo morto, pietra calcare, 1554-64, chiesa di Saint Etienne a Saint-Mihiel Ligier Richier (Saint-Mihiel, 15 settembre 1500 – Ginevra, 8 agosto 1567) è stato uno scultore francese che adottò, su un fondamento di cultura gotica, i modi stilistici del primo Rinascimento. Al servizio della corte del duca di Lorena, realizzò numerose ed importanti opere che oggi si conservano soprattutto nei dipartimenti della Mosa e della Meurthe e Mosella, nella regione della Lorena. Indic...

 

 

Yamaha YZF1000R Thunderace adalah sepeda motor yang diproduksi oleh Yamaha dari tahun 1996 hingga tahun 2003. Thunderace merupakan motor lima-katup mesin empat-silinder berasal dari FZR1000, dan frame diadaptasi dari YZF750R. Referensi Wikimedia Commons memiliki media mengenai Yamaha YZF1000R Thunderace. 1996 Yamaha YZF1000R Thunderace Fireblade on Steroids motorcycle.com review Yamaha YZF1000R Thunderace (1996-2003) Motorcyclenews.com Review

 

 

طواف نيوشبلاد للسيدات 2016 تفاصيل السباقسلسلة11. سباق أوملوب هيت نيوسبلاد للسيداتمنافسةسباق الدراجات على الطريق للسيدات 2016 1.1‏التاريخ27 فبراير 2016المسافات123 كمالبلد بلجيكانقطة البدايةخنتنقطة النهايةخنتعدد المتسابقين في البداية190عدد المتسابقين في النهاية112متوسط السرعة36...

Disambiguazione – Se stai cercando altri significati, vedi Obolo (disambigua). Questa voce o sezione sull'argomento metrologia non cita le fonti necessarie o quelle presenti sono insufficienti. Puoi migliorare questa voce aggiungendo citazioni da fonti attendibili secondo le linee guida sull'uso delle fonti. Metaponto Demetra ΟΒΟΛΟΣ - Spiga di grano Æ obolo Un obolo (in greco antico: ὀβολός?, obolòs, spiedo di ferro, che inizialmente era usato per il baratto delle merci...

 

 

本條目存在以下問題,請協助改善本條目或在討論頁針對議題發表看法。 此條目需要擴充。 (2013年1月1日)请協助改善这篇條目,更進一步的信息可能會在討論頁或扩充请求中找到。请在擴充條目後將此模板移除。 此條目需要补充更多来源。 (2013年1月1日)请协助補充多方面可靠来源以改善这篇条目,无法查证的内容可能會因為异议提出而被移除。致使用者:请搜索一下条目的...

 

 

Local authority elections in Ireland 1920 Irish local elections ← 1914 January & June 1920 1924 (Northern Ireland)1925 (Irish Free State) → All 1806 councillors across Ireland   First party Second party Third party   Leader Éamon de Valera Thomas Johnson Edward Carson Party Sinn Féin Labour Irish Unionist Councillors 550 394 355 Elections were held in January and June 1920 for the various county and district councils of Ireland. The elections were organis...

Triathlon at the 2014 Asian GamesVenueSongdo Central ParkDates25–26 September 2014Competitors65 from 15 nations← 20102018 → Triathlon at the 2014 Asian Games was held at the Songdo Central Park, Incheon, South Korea from September 25 to 26, 2014. Both men and women competed in individual events, plus a mixed-gendered relay event. The individual triathlon contains three components: a 1.5 km (0.93 mi) swim, 40 km (25 mi) cycle, an...

 

 

AbiWord AbiWord screenshotTipePengolah kata Versi pertama01 Desember 1998 (1998-12-01)Versi stabil 3.0.5 (3 Juli 2021) GenreWord processorLisensiGNU General Public LicenseBahasaDaftar bahasa Multilingual[1] Bagian dariGNOME Office Karakteristik teknisSistem operasiLinux dan BSD PlatformWindows Bahasa pemrogramanC++ Format kodeDaftarEPUB 2, AbiWord Document, OpenDocument Text file format family dan AbiWord Document Template Format berkasDaftarHyperText markup language, Office Open...

 

 

You can help expand this article with text translated from the corresponding article in Slovak. (January 2015) Click [show] for important translation instructions. View a machine-translated version of the Slovak article. Machine translation, like DeepL or Google Translate, is a useful starting point for translations, but translators must revise errors as necessary and confirm that the translation is accurate, rather than simply copy-pasting machine-translated text into the English Wikipe...

تورو نارا معلومات شخصية الميلاد سنة 1980 (العمر 43–44 سنة)  سايتاما مواطنة اليابان  الحياة العملية المهنة مؤدي أصوات اللغات اليابانية  المواقع IMDB صفحته على IMDB  تعديل مصدري - تعديل   تورو نارا (奈良徹 نارا تورو) هو مؤدي أصوات ياباني ولد في 7 مايو في محافظة سايتاما.[1...

 

 

An F-16 Fighting Falcon of the United States Air Force in flight The United States Armed Forces uses a wide variety of military aircraft across the respective aviation arms of its various service branches. The numbers of specific aircraft listed in the following entries are estimates from published sources and may not be exhaustive. For aircraft no longer in service, see the list of military aircraft of the United States. Air Force See also: United States Air Force § Aircraft inventory...

 

 

FLiBe (2LiF-BeF2) cair. Garam cair adalah garam yang berbentuk padat pada suhu dan tekanan standar tetapi berubah fase menjadi cair karena kenaikan suhu. Suatu garam yang normalnya berbentuk cair meskipun pada suhu dan tekanan standar biasanya disebut cairan ionik suhu ruang, meskipun secara teknis garam cair adalah bagian dari cairan ionik. Penggunaan Garam cair memiliki beragam kegunaan. Campuran garam klorida cair umumnya digunakan sebagai penangas pada perlakuan panas beragam logam paduan...

Women's individual compound at the 2014 Asian GamesVenueGyeyang Asiad Archery FieldDates23–27 SeptemberCompetitors38 from 13 nationsMedalists  Choi Bo-min   South Korea Seok Ji-hyun   South Korea Trisha Deb   India2022 → Archery at the2014 Asian GamesRecurveIndividualmenwomenTeammenwomenCompoundIndividualmenwomenTeammenwomenvte Main article: Archery at the 2014 Asian Games The women's individual compound archery co...

 

 

العلاقات الفنزويلية الكندية فنزويلا كندا   فنزويلا   كندا تعديل مصدري - تعديل   العلاقات الفنزويلية الكندية هي العلاقات الثنائية التي تجمع بين فنزويلا وكندا.[1][2][3][4][5] مقارنة بين البلدين هذه مقارنة عامة ومرجعية للدولتين: وجه المقارنة فنزو�...