Version française
Home     About     Download     Resources     Contact us    
Browse thread
Ocaml compiler features
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Ocaml compiler features
On Tue, 2007-01-16 at 02:11 +0000, Jon Harrop wrote:

> try ... finally is useful when closing file handles.

[]

> Solution is to box and unbox, moving the tail-recursive call outside the try 
> block:
> 
>   let rec read ?(t=[]) ch =
>     match try Some(input_line ch) with End_of_file -> None with
>     | Some h -> read ~t:(h::t)
>     | None -> t
> 
> Inelegant.

But what I do all the time to eliminate exceptions, which in general
I dislike. In my context

  let entry = try Some (Hasthtbl.find tbl key) with Not_found -> None in
  match entry with 
  | Some v ->
  | None ->

No issue of recursion here. Of course, it is easy to just define
the first line as a function, encapsulating the inelegance at
the expense of readers needing to know what an undocumented
function does.

But is it the job of a language to provide syntax for everything?

Usually languages provide syntax which spans the primitives
and a bit more covering really common idioms .. and leaves
the rest to the library.

A too rich syntax is harder to learn IMHO, for example
Ocaml classes are hard to learn. I've been writing Ocaml
for a while and still have no idea what the difference
between a method interface in a class type and a virtual
method is.


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net