caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [newbie] Caml Light vs Objective Caml
@ 2000-08-18 15:35 serge777  
  2000-08-20 19:50 ` Pierre Weis
  0 siblings, 1 reply; 2+ messages in thread
From: serge777   @ 2000-08-18 15:35 UTC (permalink / raw)
  To: caml-list

Hello, All.

You know, there are no english textbook on O'Caml.
Manual is not the best choice for a novice.
So I am trying to study Ocaml language using "The Functional
Approach to Programming" of Guy Cousineau and Michel Mauny, 
which is actually about Caml Light. 

Some Caml Light code from this book (and form others) does not work 
for Ocaml, for example, Ocaml report a syntax
error for a definition from page 25
  
 let neg = fun  true  -> false | false -> true ;;
  
1) Could anyone point out other known basic discrepancy between Caml   
Light and Ocaml that were not mentioned in the FAQ?
  
2) I know there is a French book "Diveloppement d'applications avec   
Objective Caml". Is it suits for studying functional programming and 
OCaml for peoples without any background in the functional programming?

3) Why did the meaning of "fun" change?
  
Thank you in advance.
  
Sergei.
  


--== Sent via Deja.com http://www.deja.com/ ==--
Before you buy.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [newbie] Caml Light vs Objective Caml
  2000-08-18 15:35 [newbie] Caml Light vs Objective Caml serge777  
@ 2000-08-20 19:50 ` Pierre Weis
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre Weis @ 2000-08-20 19:50 UTC (permalink / raw)
  To: serge777; +Cc: caml-list

[...]
> Some Caml Light code from this book (and form others) does not work 
> for Ocaml, for example, Ocaml report a syntax
> error for a definition from page 25
>   
>  let neg = fun  true  -> false | false -> true ;;

Yes, you should write function instead of fun here.

> 1) Could anyone point out other known basic discrepancy between Caml   
> Light and Ocaml that were not mentioned in the FAQ?

There are a few of them, namely:

- predefined identifiers that has changed (module vect is now module Array)
- module access conventions (module__ident is now Module.ident), hence
String.sub, instead of sub_string, and String.blit instead of blit_string
- case conventions have been enforced in Objective Caml.

> 2) I know there is a French book "Diveloppement d'applications avec 
> Objective Caml". Is it suits for studying functional programming and 
> OCaml for peoples without any background in the functional programming?

It is a good book with many interesting examples, worth reading. There
are a lot of other french books for beginners, have a look at

 http://pauillac.inria.fr/caml/books-eng.html

> 3) Why did the meaning of "fun" change?

The raw ``meaning'' is still the same: fun introduces a function
definition; however the syntax of the construction, and the kind of
function definitions the fun keyword introduces has changed.  Hence,
this is one of the more difficult changes you have to make when you
want to translate to O'Caml some code that heavily uses this
construct. I summarize here the differences:

What is perfectly equivalent:
-----------------------------

Introducing a curried function with multiple arguments, as in

fun x y z -> expression

What has slightly changed:
--------------------------

Introducing a pattern matching function with 1 argument; you must
change the keyword fun to the keyword function. Hence

fun true  -> false | false -> true becomes

function true  -> false | false -> true

What has completely changed:
----------------------------

In Objective Caml, the notion of ``curried pattern matching'' (as
defined in older versions of Caml) has been removed, because this
feature has been considered as having a too questionable (and complex
to understand) semantics.

The ``curried pattern matching'' is the ability to performs multiple
pattern matching in parallel, here multiple pattern matching when
defining a function. Instead of the O'Caml code

 fun x y ->
  match x, y with
  | 1, 1 -> bli
  | _, 0 -> bla
  | _, _ -> blu

you could write the Caml Light specific fragment

 fun
 | 1 1 -> bli
 | _ 0 -> bla
 | _ _ -> blu

So you need to perform the converse transformation, which is
fortunately easy if not completely mechanical.

> Thank you in advance.
>   
> Sergei.

You're welcome.

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-08-20 19:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-18 15:35 [newbie] Caml Light vs Objective Caml serge777  
2000-08-20 19:50 ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).