Talk:Caml
This article is rated Start-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||
|
Requested move
[edit]- The following discussion is an archived debate of the proposal. Please do not modify it. Subsequent comments should be made in a new section on the talk page. No further edits should be made to this section.
The result of the debate was move. -- Kjkolb 05:17, 27 August 2006 (UTC)
Categorical Abstract Machine Language → Caml – No longer an acronym. Should get an otheruses or similar template referring to CAML. Qwertyus 23:53, 20 August 2006 (UTC)
Survey
[edit]Add "* Support" or "* Oppose" followed by an optional one-sentence explanation, then sign your opinion with ~~~~
- Support Qwertyus 23:53, 20 August 2006 (UTC)
Discussion
[edit]Add any additional comments
- The above discussion is preserved as an archive of the debate. Please do not modify it. Subsequent comments should be made in a new section on this talk page. No further edits should be made to this section.
Does one really need a reference to claim that a function is more easily expressed as a function? [in a functional form]
Caml vs OCaml
[edit]I do not know Caml or OCaml so this is a request for clarification. Should the Caml page talk about OCaml? For example, the statement "...it is easy to create and pass around functions in OCaml programs." does not explicitly say if the same is true from Caml without object extensions. Jaimico 09:58, 4 June 2007 (UTC)
Better example of Higher Order Function
[edit]I do not know CAML nor OCAML, I just used Standard ML a looooooong time ago!
I came to this article to know about this descendant of ML, because I want to understand a program in OCAML.
I did not find what I needed, this article is incomplete.
The example on Higher Order Functions is not right at all, you can implement that derivate function in plain C language, which is not higher order. You can write something like:
float p(float x) { return 3*x*x-1; }
float d(float delta, float (*f)(float), float x) { return (f(x+delta)-f(x))/delta; }
int main(){ printf("d(3x^2-1)/dx at x=3.0 is :%-.6f\n",d(0.00001,p,3.0); return 0;}
The C functions can return pointers to functions, but can not return new functions. Some tricks can be done, and C++ allows overloading, but there are no higher order functions. It is totally unnatural in C/C++, although some visitor classes and other virtual classes may be used in a similar way as the functional forms in the Ocaml example below.
To clarify the it I wrote the following examples of higher order functions.
The first maps a binary tree of 'a to a binary tree of 'b applying a function f : 'a -> 'b, to each Leaf, i.e. changes each (Leaf x) to (Leaf (f x)), preserving the structure of the tree:
(* a polymorphic data structure, 'a is a variable that ranges on types *)
type 'a binTree =
| Leaf of 'a
| Tree of 'a binTree * 'a binTree
;;
let rec mapBinTree f tree =
match tree with
| Leaf v -> Leaf (f v)
| Tree (left, right) -> Tree (mapBinTree f left, mapBinTree f right)
;;
Binary trees can be folded or reduced (both terms are used in the programming argot) by replacing each constructor function by other functions. This higher order function is important because it generalize the pattern of many recursive programs. Higher order functions return functions as values, something that does not happen in the example in the article.
Here is the foldBinTree function, followed by a new definition of mapBinTree in terms of foldBinTree:
let rec foldBinTree f_t f_l tree =
match tree with
| Leaf v -> f_l v
| Tree (left, right) -> f_t (foldBinTree f_t f_l left, foldBinTree f_t f_l right)
;;
let otherMapBinTree f = foldBinTree (fun (l,r) -> Tree (l,r)) (fun n -> Leaf (f n));;
Here are some examples:
let is_even n = (n mod 2 = 0);;
let is_odd n = (n mod 2 = 1);;
(* note that the following definitions are shorter because both have the structure generalized by the foldBinTree function *)
let uOR (a,b) = a || b;;
let has_even_leaf = foldBinTree uOR is_even ;;
let has_odd_leaf = foldBinTree uOR is_odd ;;
The above functions are much more shorter and neat than:
let rec other_has_even_leaf tree =
match tree with
| Leaf v -> is_even v
| Tree (left, right) -> other_has_even_leaf left || other_has_even_leaf right
;;
let rec other_has_odd_leaf tree =
match tree with
| Leaf v -> is_odd v
| Tree (left, right) -> other_has_odd_leaf left || other_has_odd_leaf right
;;
you can try the following examples:
let example = Tree (Tree (Leaf 3, Leaf 4), Tree (Tree (Leaf 3, Leaf 4), Leaf 5));;
has_odd_leaf example;;
has_even_leaf example;;
mapBinTree (fun n -> 2 * n) example;;
mapBinTree (fun n -> 2 * n + 1) example;;
has_odd_leaf (mapBinTree (fun n -> 2 * n) example);;
has_even_leaf (mapBinTree (fun n -> 2 * n) example);;
otherMapBinTree (fun n -> 2 * n) example;;
otherMapBinTree (fun n -> 2 * n + 1) example;;
has_odd_leaf (otherMapBinTree (fun n -> 2 * n + 1) example);;
has_even_leaf (otherMapBinTree (fun n -> 2 * n + 1) example);;
The examples in the article are not clear, I mean they do not highlight the advantage to use a functional language like Caml.
After writing the above example, I discovered there is a page about OCaml with good examples. As I said before, I do not know Caml nor OCaml (if it is more than an implementation of Caml). But Caml is derived from ML a language whose formal operational semantics where defined. Given the people involved in its genesis It is highly probable that Caml, OCaml, etc. have a formal semantics defined too. Although strange things may happen, Haskell 98 did not had a formal semantics. Unbelievable but true!
So I suggest to work more on such things, like the language semantics, the functional forms (like map, fold, etc.) included in the standard library, the characteristics of it's type system. How to deal with laziness (has delay and force?), etc. When that is finished, this article may be merged with the Ocaml, for that reason a sight of that article should help to work in an style which easies the process of merging.
Also the people active in that page, may work on the subjects mentioned above, in that page, but it would be healthy to work coordinately.
2017
[edit]"OCaml, as of 2017 the main implementation of Caml"
This whole article is misleading, since the Caml language itself is not anymore in development and its fork OCaml is "the main implementation since over a decade. — Preceding unsigned comment added by 194.96.126.235 (talk) 05:36, 1 November 2017 (UTC)