Discussion:
sites on difference between OCaml, f#, Haskell
(too old to reply)
Xah Lee
2009-01-20 04:44:20 UTC
Permalink
Hi,

could anyone give me some site or blog that discuss differences
between OCaml and f#. Hard to search the web and find a good site...

in particular, i'm interested in syntactical differences between OCaml
and f#.

needn't be some comprehensive or fair... just want a quick summary.

Thanks.

Xah
∑ http://xahlee.org/


Vend
2009-01-20 16:33:58 UTC
Permalink
Post by Xah Lee
Hi,
could anyone give me some site or blog that discuss differences
between OCaml and f#. Hard to search the web and find a good site...
in particular, i'm interested in syntactical differences between OCaml
and f#.
I'm not sure but I suspect that they are the same kind of differences
between Java and C#.
Post by Xah Lee
needn't be some comprehensive or fair... just want a quick summary.
Thanks.
  Xah
∑http://xahlee.org/

Jon Harrop
2009-01-20 16:54:36 UTC
Permalink
Post by Xah Lee
Hi,
could anyone give me some site or blog that discuss differences
between OCaml and f#. Hard to search the web and find a good site...
http://strangelights.com/fsharp/wiki/default.aspx/FSharpWiki/FSharpAndOCaml.html
Post by Xah Lee
in particular, i'm interested in syntactical differences between OCaml
and f#.
Overloading instead of separate operators. From OCaml:

let sqr x = x *. x

to F#:

let (sqr: float) = x * x

Many uniform types in F# (signed and unsigned byte, int16, int32, int64,
float32, float64, complex64 written as 6uy, 6s, 6, 6L, 1.2f, 1.2) compared
to few non-uniform types in OCaml (int, Int32.t, Int64.t, float, Complex.t
written 6, 6l, 6L, 1.2, { Complex.re = 1.2; im = 0.0 }).

Immutable unicode strings in F# as "Hello world!" and byte strings as "Hello
world!"B. In vanilla OCaml, only mutable byte strings as "Hello world!".

Also, OCaml has macros written as <:expr< 1+2 >> with many syntax extensions
where as F# does not but it does have quotations written <@ 1+2 @> and <@@
1+2 @@> whereas OCaml does not.

OCaml obviously also has syntax for its many features that are not available
in F#.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u
Jon Harrop
2009-01-20 17:14:11 UTC
Permalink
Post by Jon Harrop
let sqr x = x *. x
let (sqr: float) = x * x
Also overloading of indexing from OCaml:

let f hashtbl string array index =
Hashtbl.find index hashtbl,
string.(index),
array.[index]

to F#:

let f (hashtbl: Hashtbl.t) (string: string) (array: _ array) index =
hashtbl.find index,
string.[index],
array.[index]

I think type annotations are subtly different. This annotates the type of
the tuple (a,b) in OCaml:

let (a, b: int * int) = 2, 3

but the same syntax only annotates the type of "b" in F#:

let (a, b: int) = 2, 3

Oh, and perhaps the largest syntactic difference is the use of explicit
whitespace-insensitive syntax in OCaml compared to the ubiquity of
indentation-sensitive syntax in F#.

Another different is that parameterized types in OCaml:

('a, 'b) Hashtbl.t

may be written in C++/C# style in F#:

Hashtbl.t<'a, 'b>
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u
Xah Lee
2009-01-21 01:13:59 UTC
Permalink
Thanks Jon.
Post by Jon Harrop
Oh, and perhaps the largest syntactic difference is the use of explicit
whitespace-insensitive syntax in OCaml compared to the ubiquity of
indentation-sensitive syntax in F#.

can you elaborate on this? some examples?

btw, i'm learning ocaml because it seems all major theorem proving
assistant are written in ml/ocaml, and i need to use theorem provers.

Xah
∑ http://xahlee.org/


Post by Jon Harrop
Post by Jon Harrop
let sqr x = x *. x
let (sqr: float) = x * x
let f hashtbl string array index =
Hashtbl.find index hashtbl,
string.(index),
array.[index]
let f (hashtbl: Hashtbl.t) (string: string) (array: _ array) index =
hashtbl.find index,
string.[index],
array.[index]
I think type annotations are subtly different. This annotates the type of
let (a, b: int * int) = 2, 3
let (a, b: int) = 2, 3
Oh, and perhaps the largest syntactic difference is the use of explicit
whitespace-insensitive syntax in OCaml compared to the ubiquity of
indentation-sensitive syntax in F#.
('a, 'b) Hashtbl.t
Hashtbl.t<'a, 'b>
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.http://www.ffconsultancy.com/?u
Loading...