Previous week Up Next week

Hello

Here is the latest Caml Weekly News, for the week of November 06 to 13, 2012.

  1. Google+ page
  2. OASIS, package managers and misc. poll
  3. parameterized classes, modules & polymorphic variants
  4. RTT: Run-time types for OCaml
  5. Cyclic data structures: internal representation
  6. Other Caml News

Google+ page

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2012-11/msg00064.html

Deep in this thread, Paolo Donadeo announced:
For what it's worth, Christophe's logo has been stolen (by me) and has
become the icon of the (official?) Google+ page of the language :-)

<ad type="shameless">
https://plus.google.com/u/0/113075529629418110825
</ad>
      

OASIS, package managers and misc. poll

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2012-11/msg00071.html

gildor478 announced:
If you have trouble viewing or submitting this form, you can fill it out online:
https://docs.google.com/spreadsheet/viewform?fromEmail=true&formkey=dE1jM1JSTGdHVV8wTWZxenV4cEkwVlE6MQ

One day, OASIS-DB will be able to automatically create package and
repositories. We need to know what OASIS user wish to focus our effort
on a few package manager.

Preferred package manager Choose the package manager oasis-db should
support

    GODI
    odb.ml
    OPAM
    native Debian packages
    native RPM packages (Fedora, Centos)
    non, OASIS should provide a package manager itself

Preferred build system OASIS support by design ocamlbuild, but there
are some other build system around. Which one do you think are worth
to be supported by OASIS.

    ocamlbuild
    OCamlMakefile
    OMake
    ocp-build
    custom scripts
    native Makefile
      

parameterized classes, modules & polymorphic variants

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2012-11/msg00070.html

Didier Cassirame asked and Jacques Garrigue replied:
> I have been trying recently to combine classes, modules and variants
> in the following fashion:
>
> module A1 = struct
>
> class ['a] t = object
> constraint 'a = [>`a]
> method m : 'a -> string = function `a -> "a" | `a1 -> "a1" | _ -> "_"
> end
>
> end;;
>
> […]
>
> module type A = sig
>
> class ['a] t : object
> constraint 'a = [>`a]
> method m : 'a -> string
> end
>
> end;;
>
> type m = (module A);;
>
> let l: m list = [ (module A1); (module A2); (module A3)];;
>
> --------------------------------
>
> Unfortunately the list typecheck fails. However, making a list of
> class instances from A1.t, A2.t, A3.t succeed, with the type:
>
> [> `a | `a1 | `a2 | `a3 ] ct list
>
> ct being defined as equal to A.t.
>
> I thought that perhaps I should parameterize the type m from the type
> parameter 'a of A.t to solve my problem, but I am not sure of the
> syntax, or if it's the problem. Does anyone have an idea?

Actually the parameterization would not help here, since you want to put them
all in the same list.
The idea of using first-class modules is to be explicit about types, so using
an explicit type definition for a solves the problem.

Jacques Garrigue

module A1 = struct
type a = private [> `a | `a1]

class t = object
method m : a -> string = function `a -> "a" | `a1 -> "a1" | _ -> "_"
end
end;;

module A2 = struct
type a = private [> `a | `a2]

class t = object
method m : a -> string = function `a -> "a" | `a2 -> "a2" | _ -> "_"
end
end;;

module A3 = struct
type a = private [> `a | `a3]

class t = object
method m : a -> string = function `a -> "a" | `a3 -> "a3" | _ -> "_"
end
end;;

module type A = sig
type a = private [> `a]
class t : object
method m : a -> string
end
end;;

type m = (module A);;

let l: m list = [ (module A1); (module A2); (module A3)];;
      

RTT: Run-time types for OCaml

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2012-11/msg00076.html

Tiphaine Turpin announced:
I would like to announce the first release of RTT: an implementation of
run-time types for OCaml.

http://rtt.forge.ocamlcore.org/

Run-time types make it possible to write generic printers such as
to_string: 'a -> string (for all 'a) which is useful e.g., for
debugging. The present solution is implemented as a fully automatic
program transformation which supports polymorphism naturally, and is
rather orthogonal to other existing work regarding advanced "typed"
representation of types using GADTs (the representation used here is
untyped).

Using RTT amounts to calling Rtt.to_string, Rtt.pprint... with a
modification of the compilation command to invoke the rtt preprocessor.

This tool is experimental, does not support all OCaml features (GADTs,
objects...), and is unlikely to handle any real-world program readily,
but it can at least bootstrap itself or process most of the standard
library, and it shows the feasibility of this program-transformation
approach.
      

Cyclic data structures: internal representation

Archive: https://sympa.inria.fr/sympa/arc/caml-list/2012-11/msg00079.html

Jean-Baptiste Jeannin asked and Dmitry Grebeniuk replied:
> - is there any easy way to check if a list is cyclic or not? The only way I
> see is to go down the list, checking at every step if this particular
> sublist has already been seen. But it's rather heavy.

> - the documentation on the = sign
> (http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html)
> mentions that "Equality between cyclic data structures may not terminate."
> It seems to terminate if one or the other of the data structures is not
> cyclic. Does it ever terminate when both data sstructures are cyclic, or
> does it always loop?

Both these questions are solved with my library ocaml-cyclist:
https://forge.ocamlcore.org/projects/ocaml-cyclist/
I don't remember exact details, but generally I use
"tortoise and hare" algorithm.

Also note that lists with a cycle can also contain some prefix
that doesn't appear in the cycle (it happens when list with cycle
is appended to "linear" list). That's also covered by ocaml-cyclist:

value length : list 'a -> (int * int);
(** Returns [(prefix_len, cycle_len)] of the argument.
(0, 0) for empty list, (n, 0) for linear list,
(0, n) for circular list, (n, m) for generic-shaped
cyclic list. (n, m > 0)
*)

As for equality, you can use

value for_all2 : ?strict:bool ->
('a -> 'b -> bool) -> list 'a -> list 'b -> bool;

to write the code like

let list_eq a b = Cyclist.for_all2 ~strict:true ( = ) a b

which will run correctly. However, the following lists will be
considered equal: [{1; 2; 3}] and [1; 2; {3; 1; 2; 3; 1; 2}] (curly braces
denote the cycle of list; it's for illustration purposes only).
Using other library functions you can strenghten your equality
relation.
      

Other Caml News

From the ocamlcore planet blog:
Thanks to Alp Mestan, we now include in the Caml Weekly News the links to the
recent posts from the ocamlcore planet blog at http://planet.ocamlcore.org/.

Maps, sets, and hashtables in core:
  https://ocaml.janestreet.com/?q=node/112

How to implement dependent type theory II:
  http://math.andrej.com/2012/11/11/how-to-implement-dependent-type-theory-ii/

Master and Footballer:
  https://forge.ocamlcore.org/projects/mnf/

Resolution of label and constructor names: the devil in the details:
  http://gallium.inria.fr/~scherer/gagallium/resolving-field-names-2/index.html

How to implement dependent type theory I:
  http://math.andrej.com/2012/11/08/how-to-implement-dependent-type-theory-i/

Bisect 1.3:
  http://caml.inria.fr/cgi-bin/hump.cgi?contrib=650

Bolt 1.4:
  http://caml.inria.fr/cgi-bin/hump.cgi?contrib=699

Using well-disciplined type-propagation to disambiguate label and constructor names:
  http://gallium.inria.fr/~scherer/gagallium/resolving-field-names/index.html

RTT:
  https://forge.ocamlcore.org/projects/rtt/
      

Old cwn

If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.

If you also wish to receive it every week by mail, you may subscribe online.


Alan Schmitt