[Pkg-ocaml-maint-commits] [ocaml-deriving-ocsigen] 01/06: Imported Upstream version 0.7

Stéphane Glondu glondu at moszumanska.debian.org
Fri Sep 4 11:11:46 UTC 2015


This is an automated email from the git hooks/post-receive script.

glondu pushed a commit to branch master
in repository ocaml-deriving-ocsigen.

commit 6e25289f4bc98a1f228d47ca17aee7160ac3b8ed
Author: Stephane Glondu <steph at glondu.net>
Date:   Thu Sep 3 17:43:49 2015 +0200

    Imported Upstream version 0.7
---
 .gitignore                   |   2 +-
 .jenkins.sh                  |  15 ++
 CHANGES                      |   6 +
 Makefile                     |  82 ++++------
 _oasis                       |  19 ++-
 configure                    |   7 +-
 doc/apiref-intro             |  40 +++++
 doc/manual-wiki/classes.wiki | 230 +++++++++++++++++++++++++++
 doc/manual-wiki/intro.wiki   | 367 +++++++++++++++++++++++++++++++++++++++++++
 lib/META.ab                  |  16 +-
 lib/deriving_Dump.ml         |  14 +-
 lib/deriving_Eq.ml           |   7 +
 lib/deriving_Eq.mli          |   1 +
 lib/deriving_interned.ml     |  22 +--
 myocamlbuild.ml              |  41 +++++
 opam                         |  26 +++
 opam/descr                   |   1 -
 opam/opam                    |  16 --
 opam/url                     |   1 -
 setup.ml                     |  11 +-
 syntax/common/extend.ml      |  38 ++++-
 syntax/common/utils.ml       |   9 +-
 22 files changed, 861 insertions(+), 110 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5e1d2b9..c0bf3f0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,7 +10,7 @@ setup.data
 syntax/common/id.ml
 *.bak
 *.ba0
-setup-dev.exe
+setup.exe
 *.mllib
 *.mlpack
 lib/META
diff --git a/.jenkins.sh b/.jenkins.sh
new file mode 100644
index 0000000..c6b3350
--- /dev/null
+++ b/.jenkins.sh
@@ -0,0 +1,15 @@
+
+opam pin add --no-action deriving .
+opam install type_conv
+opam install --deps-only deriving
+opam install --verbose deriving
+
+do_build_doc () {
+  make wikidoc
+  cp -Rf doc/manual-wiki/*.wiki ${MANUAL_SRC_DIR}
+  cp -Rf _build/deriving-api.wikidocdir/*.wiki ${API_DIR}
+}
+
+do_remove () {
+  opam remove --verbose deriving
+}
diff --git a/CHANGES b/CHANGES
index 940f9b4..f173d61 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+== 0.7
+
+  * Compatibility with ocaml-4.02 (Peter Zotoz, Hugo Heuzard)
+  * Fix toplevel usage (Vincent Bernardoff)
+  * Class: add equality for sets (Jeremy Yallop)
+
 == 0.6
 
   * Added a 'Default' class (Hugo Heuzard)
diff --git a/Makefile b/Makefile
index 1e526ee..db13090 100644
--- a/Makefile
+++ b/Makefile
@@ -1,65 +1,49 @@
-# Makefile
-# --------
-# Copyright : (c) 2012, Jeremie Dimino <jeremie at dimino.org>
-# Licence   : BSD3
-#
-# Generic Makefile for oasis project
-
-# Set to setup.exe for the release
-SETUP := setup-dev.exe
-
-ifeq ($(shell ocamlc -v | grep -q "version 3.12"; echo $$?),0)
-# FIX for ocaml version 3.12, link with toplevellib.cma
-TOPLEVEL := toplevellib.cma
-else
-TOPLEVEL := -package compiler-libs.toplevel
-endif
-
-# Default rule
-default: build
-
-# Setup for the development version
-setup-dev.exe: _oasis setup.ml
-	grep -v '^#' setup.ml > setup_dev.ml
-	ocamlfind ocamlc -o $@ -linkpkg -package ocamlbuild,oasis.dynrun $(TOPLEVEL) setup_dev.ml || true
-	rm -f setup_dev.*
-
-# Setup for the release
-setup.exe: setup.ml
-	ocamlopt.opt -o $@ $< || ocamlopt -o $@ $< || ocamlc -o $@ $<
-	rm -f setup.cmx setup.cmi setup.o setup.obj setup.cmo
+# OASIS_START
+# DO NOT EDIT (digest: 9a60866e2fa295c5e33a3fe33b8f3a32)
+
+SETUP = ./setup.exe
 
-build: $(SETUP) setup.data
-	./$(SETUP) -build $(BUILDFLAGS)
+build: setup.data $(SETUP)
+	$(SETUP) -build $(BUILDFLAGS)
 
-doc: $(SETUP) setup.data build
-	./$(SETUP) -doc $(DOCFLAGS)
+doc: setup.data $(SETUP) build
+	$(SETUP) -doc $(DOCFLAGS)
 
-test: $(SETUP) setup.data build
-	./$(SETUP) -test $(TESTFLAGS)
+test: setup.data $(SETUP) build
+	$(SETUP) -test $(TESTFLAGS)
 
 all: $(SETUP)
-	./$(SETUP) -all $(ALLFLAGS)
+	$(SETUP) -all $(ALLFLAGS)
 
-install: $(SETUP) setup.data
-	./$(SETUP) -install $(INSTALLFLAGS)
+install: setup.data $(SETUP)
+	$(SETUP) -install $(INSTALLFLAGS)
 
-uninstall: $(SETUP) setup.data
-	./$(SETUP) -uninstall $(UNINSTALLFLAGS)
+uninstall: setup.data $(SETUP)
+	$(SETUP) -uninstall $(UNINSTALLFLAGS)
 
-reinstall: $(SETUP) setup.data
-	./$(SETUP) -reinstall $(REINSTALLFLAGS)
+reinstall: setup.data $(SETUP)
+	$(SETUP) -reinstall $(REINSTALLFLAGS)
 
 clean: $(SETUP)
-	./$(SETUP) -clean $(CLEANFLAGS)
+	$(SETUP) -clean $(CLEANFLAGS)
 
 distclean: $(SETUP)
-	./$(SETUP) -distclean $(DISTCLEANFLAGS)
+	$(SETUP) -distclean $(DISTCLEANFLAGS)
+	$(RM) $(SETUP)
+
+setup.data: $(SETUP)
+	$(SETUP) -configure $(CONFIGUREFLAGS)
 
 configure: $(SETUP)
-	./$(SETUP) -configure $(CONFIGUREFLAGS)
+	$(SETUP) -configure $(CONFIGUREFLAGS)
 
-setup.data: $(SETUP)
-	./$(SETUP) -configure $(CONFIGUREFLAGS)
+setup.exe: setup.ml
+	ocamlfind ocamlopt -o $@ -linkpkg -package oasis.dynrun $< || ocamlfind ocamlc -o $@ -linkpkg -package oasis.dynrun $< || true
+	$(RM) setup.cmi setup.cmo setup.cmx setup.o
+
+.PHONY: build doc test all install uninstall reinstall clean distclean configure
+
+# OASIS_STOP
 
-.PHONY: default build doc test all install uninstall reinstall clean distclean configure
+wikidoc: $(SETUP) setup.data build
+	$(SETUP) -build deriving-api.wikidocdir/index.wiki
diff --git a/_oasis b/_oasis
index 66cb173..ba2d437 100644
--- a/_oasis
+++ b/_oasis
@@ -1,13 +1,15 @@
 OASISFormat: 0.4
 Name:        deriving
 OCamlVersion: >= 3.12.1
-Version:     0.6.1
+Version:     0.7
 Synopsis:    Extension to OCaml for deriving functions from type declarations
 Authors:     Jeremy Yallop
 License:     MIT
 BuildTools:  ocamlbuild
 FilesAB:     syntax/common/id.ml.ab,
              lib/META.ab
+Plugins: DevFiles (0.4)
+AlphaFeatures: compiled_setup_ml
 
 Flag tc
   Description: type-conv support
@@ -45,7 +47,7 @@ Library "pa_deriving_common"
   FindlibName   : common
   Pack          : true
   Modules       : Id, Utils, Type, Defs, Clusters, Base, Extend
-  BuildDepends  : camlp4,camlp4.extend,camlp4.quotations.o,optcomp
+  BuildDepends  : camlp4,camlp4.extend,camlp4.quotations.o,optcomp,bytes
 
 Library "pa_deriving_std"
   Path          : syntax/std
@@ -63,6 +65,19 @@ Library "pa_deriving_tc"
   Build$: flag(tc)
   Install$: flag(tc)
 
+Document "deriving-api"
+  Title: API reference for Deriving
+  Type: ocamlbuild (0.3)
+  Install: true
+  InstallDir: $htmldir/api
+  BuildTools: ocamldoc
+  XOCamlbuildPath: ./
+  XOCamlbuildLibraries:
+    deriving,
+    deriving.num,
+    deriving.syntax,
+    deriving.syntax.common
+
 Executable test
   Path           : tests/std
   CompiledObject : best
diff --git a/configure b/configure
index be54a2d..d2a26d1 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,9 @@
 #!/bin/sh
 
+# OASIS_START
+# DO NOT EDIT (digest: 6f7b8221311e800a7093dc3b793f67ca)
+set -e
+
 FST=true
 for i in "$@"; do
   if $FST; then
@@ -19,4 +23,5 @@ for i in "$@"; do
   esac
 done
 
-make configure CONFIGUREFLAGS="$@"
+make configure CONFIGUREFLAGS="$*"
+# OASIS_STOP
diff --git a/doc/apiref-intro b/doc/apiref-intro
new file mode 100644
index 0000000..6e00b6e
--- /dev/null
+++ b/doc/apiref-intro
@@ -0,0 +1,40 @@
+{1 Deriving - API Reference}
+
+{2 Runtime library}
+
+Runtime for deriving classes shipped with deriving.
+
+{!modules:
+Deriving_Show
+Deriving_Eq
+Deriving_Bounded
+Deriving_Enum
+Deriving_monad
+Deriving_Dump
+Deriving_Typeable
+Deriving_Pickle
+Deriving_Functor
+Deriving_Default
+}
+
+{!modules:
+Deriving_num
+}
+
+{2 Syntax}
+The {e deriving.syntax.common} package contains modules needed to
+write deriving classes.
+
+{!modules:
+Id
+Utils
+Type
+Defs
+Clusters
+Base
+Extend
+}
+
+{2 Index}
+
+{!indexlist}
diff --git a/doc/manual-wiki/classes.wiki b/doc/manual-wiki/classes.wiki
new file mode 100644
index 0000000..21d1e20
--- /dev/null
+++ b/doc/manual-wiki/classes.wiki
@@ -0,0 +1,230 @@
+= Standard classes =
+== Show ==
+
+<<code language="ocaml"|
+module type Show =
+sig
+  type a
+  val format : Format.formatter -> a -> unit
+  val format_list : Format.formatter -> a list -> unit
+  val show : a -> string
+  val show_list : a list -> string
+end
+>>
+
+If you're writing your own instance then you'll find the Defaults useful. The only method you have to write yourself is format:
+
+<<code language="ocaml"|
+module Defaults (S :
+  sig
+    type a
+    val format : Format.formatter -> a -> unit
+  end) : Show with type a = S.a
+
+>>
+== Eq ==
+
+<<code language="ocaml"|
+module type Eq =
+sig
+  type a
+  val eq : a -> a -> bool
+end
+>>
+
+== Typeable ==
+
+<<code language="ocaml"|
+module TypeRep :
+sig
+  type t
+  val compare : t -> t -> int
+  val eq : t -> t -> bool
+  ...
+end
+>>
+
+The exception CastFailure is thrown when throwing_cast fails:
+
+<<code language="ocaml"|
+exception CastFailure of string
+>>
+<<code language="ocaml"|
+module type Typeable =
+sig
+  type a
+  val type_rep : unit -> TypeRep.t
+  val has_type : dynamic -> bool
+  val cast : dynamic -> a option
+  val throwing_cast : dynamic -> a
+  val make_dynamic : a -> dynamic
+  val mk : a -> dynamic
+end
+>>
+
+If you're writing your own instance (which is not recommended in this
+case!) you can just supply the type_rep method and use the Defaults
+functor:
+
+<<code language="ocaml"|
+module Defaults (T : (sig
+                        type a
+                        val type_rep : unit -> TypeRep.t
+                      end))
+  : Typeable with type a = T.a
+>>
+
+== Dump ==
+
+<<code language="ocaml"|
+module type Dump =
+  sig
+    type a
+    val to_buffer : Buffer.t -> a -> unit
+    val to_string : a -> string
+    val to_channel : out_channel -> a -> unit
+    val from_stream : char Stream.t -> a
+    val from_string : string -> a
+    val from_channel : in_channel -> a
+  end
+>>
+
+If the input doesn't match the type then deserialisation will fail
+with the exception:
+
+<<code language="ocaml"|
+exception Dump_failure of string
+>>
+
+If you're writing your own instance then you use the Defaults functor,
+which requires implementations of the methods to_buffer and
+from_stream.
+
+<<code language="ocaml"|
+
+module Defaults
+  (P : sig
+     type a
+     val to_buffer : Buffer.t -> a -> unit
+     val from_stream : char Stream.t -> a
+   end) : Dump with type a = P.a
+>>
+== Pickle ==
+<<code language="ocaml"|
+module type Pickle =
+sig
+  type a
+  module T : Typeable.Typeable with type a = a
+  module E : Eq.Eq with type a = a
+  val pickle : a -> id Write.m
+  val unpickle : id -> a Read.m
+  val to_buffer : Buffer.t -> a -> unit
+  val to_string : a -> string
+  val to_channel : out_channel -> a -> unit
+  val from_stream : char Stream.t -> a
+  val from_string : string -> a
+  val from_channel : in_channel -> a
+end
+>>
+
+If deserialisation (unmarshalling) fails then one of the following
+exceptions is thrown:
+
+
+<<code language="ocaml"|
+exception UnpicklingError of string
+exception UnknownTag of int * string
+>>
+
+As usual, you can use the Defaults method when writing your own
+instance:
+
+<<code language="ocaml"|
+module Defaults
+  (S : sig
+     type a
+     module T : Typeable.Typeable with type a = a
+     module E : Eq.Eq with type a = a
+     val pickle : a -> id Write.m
+     val unpickle : id -> a Read.m
+   end) : Pickle with type a = S.a
+>>
+
+You can also create a Pickle instance from a Dump instance, although
+you may limit the opportunities for sharing if you do:
+
+<<code language="ocaml"|
+module Pickle_from_dump
+  (D : Dump.Dump)
+  (E : Eq.Eq with type a = D.a)
+  (T : Typeable.Typeable with type a = D.a)
+  : Pickle with type a = D.a
+>>
+
+== Enum ==
+
+<<code language="ocaml"|
+module type Enum =
+  sig
+    type a
+    val succ : a -> a
+    val pred : a -> a
+    val to_enum : int -> a
+    val from_enum : a -> int
+    val enum_from : a -> a list
+    val enum_from_then : a -> a -> a list
+    val enum_from_to : a -> a -> a list
+    val enum_from_then_to : a -> a -> a -> a list
+  end
+
+>>
+
+There are two easy ways to write your own instance of Enum: you can
+supply an explicit mapping from values of your type to integers:
+
+<<code language="ocaml"|
+module Defaults
+  (E : sig type a val numbering : (a * int) list end)
+  : Enum with type a = E.a
+>>
+
+or you can supply the mapping as a pair of functions, together with suitable bounds for your type:
+<<code language="ocaml"|
+module Defaults'
+  (E : sig type a val from_enum : a -> int val to_enum : int -> a end)
+  (B : Bounded.Bounded with type a = E.a)
+  : Enum with type a = B.a
+>>
+
+== Bounded ==
+<<code language="ocaml"|
+module type Bounded =
+sig
+  type a
+  val min_bound : a
+  val max_bound : a
+end
+>>
+
+== Functor ==
+
+There is no signature for Functor, since the type of the derived
+function depends on the number of type parameters. For example, a type
+with one parameter will result in a singature
+
+<<code language="ocaml"|
+sig
+  type 'a f
+  val map : ('a -> 'b) -> 'a f -> 'b f
+end
+>>
+
+whereas a type with three parameters will generate an instance with
+signature
+
+<<code language="ocaml"|
+sig
+  type ('a,'b,'c) f
+  val map : ('a -> 'd) -> ('b -> 'e) -> ('c -> 'f) -> ('a,'b,'c) f -> ('d,'e,'f) f
+end
+>>
diff --git a/doc/manual-wiki/intro.wiki b/doc/manual-wiki/intro.wiki
new file mode 100644
index 0000000..6ae11cc
--- /dev/null
+++ b/doc/manual-wiki/intro.wiki
@@ -0,0 +1,367 @@
+= deriving examples =
+== Pretty printing ==
+
+The deriving preprocessor and library provide common functionality
+which has an obvious definition at most types. For example, it's
+usually easy, although tedious, to write a to_string function for a
+new type you've defined; deriving will save you the trouble by writing
+the function for you automatically. To call a deriving function at a
+particular type you use a special notation:
+
+
+<<code language="ocaml"|
+    Class.method<type> argument
+>>
+
+(Note that the terms "Class" and "method" are taken from Haskell's
+    type classes, and has nothing to do with OCaml's object-oriented
+    class system.)
+
+
+For example, to call the show method of the Show class to convert an
+integer to a string you would write:
+
+<<code language="ocaml"|
+Show.show<int> 3
+=>
+"3"
+>>
+
+You can also specify more complex types:
+
+<<code language="ocaml"|
+let factors = [(10,[2;5]); (11, []);  12, [2;3;4;6]]
+
+Show.show<(int * int list) list> factors
+=>
+"[(10,[2; 5]); (11, []);  12, [2; 3; 4; 6]]"
+>>
+
+To use a deriving function at a type you've defined, you need to add
+the phrase deriving (Class) to the end of your type definition. For
+example,
+
+<<code language="ocaml"|
+ type 'a tree = Leaf of 'a | Branch of 'a tree * 'a * 'a tree
+     deriving (Show)
+
+ type point = { x : float; y : float }
+     deriving (Show)
+
+ let points = Branch (Leaf {x=0.0;
+                            y=0.0;},
+                      {x=2.0; y=2.0},
+                      Branch (Leaf {x=1.0; y=1.0},
+                              {x=1.0; y=0.0},
+                              Leaf {x=0.0; y=1.0}))
+
+Show.show<point tree> points
+=>
+"Branch
+   (Leaf {x =193.11; y =132.13}, {x =211.91; y =201.11},
+    Branch
+      (Leaf {x =113.12; y =1.}, {x =12.7; y =44.1}, Leaf {x =0.; y
+      =13.41}))"
+
+>>
+
+If you want to show values of an abstract type defined in a module
+outside the module you should add the deriving annotation to the
+signature as well:
+
+
+<<code language="ocaml"|
+module IntStack : sig
+  type t
+    deriving (Show)
+
+  val empty : t
+  val push : int -> t -> t
+  val top : t -> int
+  val pop : t -> t
+end =
+struct
+  type t = Stack of int list
+     deriving (Show)
+  let empty = Stack []
+  let push item (Stack list) = Stack (item::list)
+  let top (Stack (top::_)) = top
+  let pop (Stack (_::rest)) = Stack rest
+end
+
+Show.show<IntStack.t>
+  (IntStack.push 3 (IntStack.push 4 (IntStack.push 5 IntStack.empty)))
+=>
+"Stack [3; 4; 5]"
+>>
+
+You can derive Show for most types, including recursive (and mutually
+recursive) types, normal and polymorphic variants, records, tuples and
+types containing other types for which Show has been derived. You
+can't derive Show for functions because there's usually no meaningful
+way to display them. If you have a way to display values of a type for
+which Show cannot be derived then you can always write your own
+definition and make it available to deriving; see the section
+"Extending definitions".
+
+
+== Dynamic typing ==
+
+The `Typeable' class provides operations for converting between a
+universal type `dynamic' and any other type. Converting from dynamic
+to another type succeeds only if the type specified in the conversion
+matches the type used to create the dynamic value. The upcast
+operation is called mk (or make_dynamic if you prefer to be
+verbose). The downcasts are cast, which returns an option value, and
+throwing_cast, which throws an exception if the downcast fails.
+
+
+<<code language="ocaml"|
+type 'a tree = Leaf of 'a | Branch of 'a tree * 'a * 'a tree
+  deriving (Typeable)
+
+let items =
+   [Typeable.mk<int> 3;
+    Typeable.mk<float> 3.0;
+    Typeable.mk<string tree> (Leaf "three")]
+=>
+[<abstr>; <abstr>; <abstr>]
+
+Typeable.cast<int> (List.hd items)
+=>
+Some 3
+
+Typeable.throwing_cast<int> (List.hd items)
+=>
+3
+
+Typeable.cast<float> (List.hd items)
+=>
+None
+
+Typeable.throwing_cast<float> (List.hd items)
+=>
+Exception: Typeable.CastFailure "cast failed".
+>>
+
+Casts also work between equivalent polymorphic variant types (even if
+the types used for the upcast and downcast are defined differently):
+
+<<code language="ocaml"|
+
+type 'a seq = [`Nil | `Cons of 'a * 'a seq]
+    deriving (Typeable)
+
+let l = `Cons (3, `Cons (2, `Cons (1, `Nil)))
+
+Typeable.cast<[`Cons of int * 'a|`Nil] as 'a>
+  (Typeable.mk<int seq> l)
+=>
+Some (`Cons (3, `Cons (2, `Cons (1, `Nil))))
+
+>>
+
+Casts don't work between record or normal variant types which are
+defined separately, even if the definitions are identical.
+
+<<code language="ocaml"|
+type complex = {x : float; y : float}
+  deriving (Typeable)
+
+
+type point = {x : float; y : float}
+  deriving (Typeable)
+
+Typeable.cast<point> (Typeable.mk<complex> {x : -1.0; y : 0.0})
+=>
+None
+>>
+
+However, abstraction using module signatures does not change whether
+types are interconvertible, so you can use Typeable to access the
+representation of an abstract type if you know it.
+
+
+<<code language="ocaml"|
+module T :
+sig
+  type t
+    deriving (Typeable)
+  val v : t
+end =
+struct
+  type t = int
+  val v = 12
+end
+
+Typeable.cast<int> (Typeable.mk<T.t> T.v)
+=>
+12
+>>
+
+== Equality ==
+
+There are two polymorphic equality operators in OCaml:
+
+{{{=}}} tests for structural equality.
+{{{==}}} tests for physical equality.
+Sometimes neither of these is appropriate. Instead, we want to test
+for structural equality at immutable types and physical equality
+(identity) at mutable types (as in SML). This sort of equality tests
+whether two values can be used interchangeably in a program.
+
+
+<<code language="ocaml"|
+Eq.eq<int ref> (ref 1) (ref 1)
+=>
+false
+
+let x = ref 1 in Eq.eq<int ref> x x
+=>
+true
+
+Eq.eq<int list> [1;2;3] [1;2;3]
+=>
+true
+
+type mpoint = { mutable x : float; mutable y : float}
+    deriving (Eq)
+
+Eq.eq<mpoint> {x = 1.0; y = 2.0} {x = 1.0; y = 2.0}
+=>
+false
+
+let p = {x = 1.0; y = 2.0} in Eq.eq<mpoint> p p
+=>
+true
+
+type ipoint = { x : float; y : float}
+    deriving (Eq)
+
+Eq.eq<ipoint> {x = 1.0; y = 2.0} {x = 1.0; y = 2.0}
+=>
+true
+>>
+
+== Serialisation ==
+The `Pickle' class provides operations for structure-sharing
+serialisation (marshalling). If any value to be serialised contains
+two equal subvalues then only one copy of the subvalue will be
+serialised. Cycles that are created by mutable record fields,
+including references, are preserved.
+
+All "instances" of Pickle must also be "instances" of Eq and
+Typeable. (As in Haskell, we use "instance" to mean a set of functions
+that implement the methods of a class at a particular type.)
+
+<<code language="ocaml"|
+
+type 'a tree = Leaf of 'a | Branch of 'a tree * 'a * 'a tree
+  deriving (Eq, Typeable, Pickle)
+
+type point = { x : float; y : float }
+    deriving (Eq, Typeable, Pickle)
+
+Pickle.to_string<point tree> points
+=>
+"\007\003\t\128\128\128\128\128\128\128\248?\t\128\128\128\128\128\128\128\128@\001\000\005\000\001\008\000\001\n\001\003\004\t\003\000\001\012\001\003\006\011\005\005\002\002\000\002\000\002\002\000\000\002\001\001\002\002\002"
+
+Pickle.from_string<point tree> (Pickle.to_string<point tree> points)
+=>
+Branch
+  (Leaf {x =193.11; y =132.13}, {x =211.91; y =201.11},
+   Branch
+     (Leaf {x =113.12; y =1.}, {x =12.7; y =44.1}, Leaf {x =0.; y =13.41}))
+>>
+
+You can supply a custom definition of equality (see the section
+"Extending definitions") to increase sharing: see the file
+tests/exp.ml in the distribution for an example.
+
+There is another class, `Dump', that provides simpler value-oriented
+serialisation, but doesn't deal with references or cycles.
+
+
+== Map ==
+
+Given a type ('a1,...,'an) t, the `Functor' class will derive a map operation:
+<<code language="ocaml"|
+ val map : ('a1->'b1) -> ... ('an->'bn} -> ('a1,...,'an) t -> ('b1,...,'bn) t
+>>
+
+For example,
+
+<<code language="ocaml"|
+
+type 'a tree = Leaf of 'a | Branch of 'a tree * 'a * 'a tree
+  deriving (Functor)
+
+Functor_tree.map ((+) 1) (Branch (Leaf 3, 4, Leaf 5))
+=>
+(Branch (Leaf 4, 5, Leaf 6))
+>>
+
+The <t> notation is not currently available for Functor.
+
+== Enumerations ==
+
+Enumerations provide several operations for dealing with variant types
+where all constructors have no argument.
+
+
+<<code language="ocaml"|
+Enum.enum_from_to<int> 0 10
+=>
+[0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10]
+
+type fruit = Apple | Orange | Banana | Kiwi
+   deriving (Enum)
+
+Enum.enum_from_to<fruit> Apple Kiwi
+=>
+[Apple; Orange; Banana; Kiwi]
+
+Enum.succ<fruit> Orange
+=>
+Banana
+>>
+
+== Minimum and maximum values ==
+Instances of bounded have maximum and minimum values:
+
+<<code language="ocaml"|
+type fruit = Apple | Orange | Banana | Kiwi
+   deriving (Bounded)
+
+(Bounded.min_bound<int * fruit>, Bounded.max_bound<int * fruit>)
+=>
+((-1073741824, Apple), (1073741823, Kiwi))
+>>
+
+== Extending definitions ==
+Instead of deriving a definition automatically you can provide your
+own by writing a module with the same signature as the standard
+definitions with a name formed from the class name, an underscore, and
+the name of the type constructor for which you want to provide the
+definition.
+
+<<code language="ocaml"|
+module Eq_fruit
+  : Eq.Eq with type a = fruit =
+Eq.Defaults(struct
+  type a = fruit
+  let eq l r = match l, r with
+   | Apple  , Orange
+   | Orange , Apple
+   | Apple  , Apple
+   | Orange , Orange
+   | Banana , Banana
+   | Kiwi   , Kiwi   -> true
+   | _               -> false
+end)
+
+Eq.eq<fruit list> [Apple; Orange; Banana] [Orange; Orange; Banana]
+=>
+true
+
+>>
diff --git a/lib/META.ab b/lib/META.ab
index 56b5461..c226a04 100644
--- a/lib/META.ab
+++ b/lib/META.ab
@@ -2,7 +2,6 @@ version = "$(pkg_version)"
 description = "Deriving"
 
 requires = "$(pkg_name).runtime, $(pkg_name).syntax"
-requires(syntax, preprocessor) = "$(pkg_name).syntax"
 archive(syntax, preprocessor) = "-ignore dummy"
 
 error(pkg_type_conv, pkg_deriving) = "Could not be loaded together with 'type_conv'. Please use $(pkg_name).tc instead."
@@ -14,12 +13,14 @@ package "runtime" (
   archive(byte, pkg_num) += "deriving_num.cma"
   archive(native, pkg_num) += "deriving_num.cmxa"
 
+  requires = "bytes"
+
 )
 
 package "syntax" (
 
   requires(syntax, preprocessor) = "$(pkg_name).syntax.std, $(pkg_name).syntax.classes"
-  requires(syntax, toploop) = "$(pkg_name).syntax.std, $(pkg_name).syntax.classes"
+  requires(toploop) = "$(pkg_name).syntax.std, $(pkg_name).syntax.classes"
   archive(syntax, preprocessor) = "-ignore dummy"
 
   error(pkg_type_conv, pkg_deriving.syntax, -pkg_deriving) = "Could not be loaded together with 'type_conv'. Please use $(pkg_name).syntax_tc instead."
@@ -27,7 +28,7 @@ package "syntax" (
   package "common" (
 
     requires(syntax, preprocessor) = "unix, camlp4"
-    requires(syntax, toploop) = "unix, camlp4"
+    requires(toploop) = "unix, camlp4"
 
     archive(syntax, preprocessor) = "pa_deriving_common.cma"
     archive(syntax, toploop) = "pa_deriving_common.cma"
@@ -40,7 +41,7 @@ package "syntax" (
     version = "$(pkg_version)"
 
     requires(syntax, preprocessor) = "$(pkg_name).syntax.common"
-    requires(syntax, toploop) = "$(pkg_name).syntax.common"
+    requires(toploop) = "$(pkg_name).syntax.common"
 
     error(pkg_type_conv, -pkg_deriving.syntax, -pkg_deriving) = "Could not be loaded together with 'type_conv'. Please use $(pkg_name).syntax.tc instead."
 
@@ -57,7 +58,7 @@ package "syntax" (
     version = "$(pkg_version)"
 
     requires(syntax, preprocessor) = "$(pkg_name).syntax.common, type_conv"
-    requires(syntax, toploop) = "$(pkg_name).syntax.common, type_conv"
+    requires(toploop) = "$(pkg_name).syntax.common, type_conv"
 
     exists_if = "pa_deriving_tc.cma"
 
@@ -72,7 +73,7 @@ package "syntax" (
     version = "$(pkg_version)"
 
     requires(syntax, preprocessor) = "$(pkg_name).syntax.common"
-    requires(syntax, toploop) = "$(pkg_name).syntax.common"
+    requires(toploop) = "$(pkg_name).syntax.common"
 
     exists_if = "pa_deriving_classes.cma"
 
@@ -85,12 +86,11 @@ package "syntax" (
 
 package "tc" (
   requires = "$(pkg_name).runtime, $(pkg_name).syntax_tc"
-  requires(syntax, preprocessor) = "$(pkg_name).syntax_tc"
   archive(syntax, preprocessor) = "-ignore dummy"
 )
 
 package "syntax_tc" (
   requires(syntax, preprocessor) = "$(pkg_name).syntax.tc, $(pkg_name).syntax.classes"
-  requires(syntax, toploop) = "$(pkg_name).syntax.tc, $(pkg_name).syntax.classes"
+  requires(toploop) = "$(pkg_name).syntax.tc, $(pkg_name).syntax.classes"
   archive(syntax, preprocessor) = "-ignore dummy"
 )
diff --git a/lib/deriving_Dump.ml b/lib/deriving_Dump.ml
index 4b04f73..13e356f 100644
--- a/lib/deriving_Dump.ml
+++ b/lib/deriving_Dump.ml
@@ -138,9 +138,9 @@ module Dump_string = Defaults (
       end
     and from_stream stream = 
       let len = Dump_int.from_stream stream in
-      let s = String.create len in
+      let s = Bytes.create len in
         for i = 0 to len - 1 do
-          String.set s i (Stream.next stream) (* could use String.unsafe_set here *)
+          Bytes.unsafe_set s i (Stream.next stream)
         done;
         s
   end
@@ -243,11 +243,11 @@ module Dump_via_marshal (P : sig type a end) = Defaults (
     let to_buffer buffer obj = Buffer.add_string buffer (Marshal.to_string obj [Marshal.Closures])
     let from_stream stream = 
       let readn n = 
-        let s = String.create n in
-          for i = 0 to n - 1 do
-            String.set s i (Stream.next stream)
-          done;
-          s
+        let s = Bytes.create n in
+        for i = 0 to n - 1 do
+          Bytes.set s i (Stream.next stream)
+        done;
+        s
       in
       let header = readn Marshal.header_size in
       let datasize = Marshal.data_size header 0 in
diff --git a/lib/deriving_Eq.ml b/lib/deriving_Eq.ml
index 60e45a6..ff231a1 100644
--- a/lib/deriving_Eq.ml
+++ b/lib/deriving_Eq.ml
@@ -54,6 +54,13 @@ struct
   let eq = M.equal (E.eq)
 end  
 
+module Eq_set_s_t (S : Set.S)
+  : Eq with type a = S.t =
+struct
+  type a = S.t
+  let eq = S.equal
+end  
+
 module Eq_list (E : Eq) :
   Eq with type a = E.a list =
 struct
diff --git a/lib/deriving_Eq.mli b/lib/deriving_Eq.mli
index debee1b..76a558b 100644
--- a/lib/deriving_Eq.mli
+++ b/lib/deriving_Eq.mli
@@ -26,3 +26,4 @@ module Eq_array (E : Eq) : Eq with type a = E.a array
 module Eq_list (E : Eq)  : Eq with type a = E.a list
 module Eq_option (E : Eq): Eq with type a = E.a option
 module Eq_map_s_t (E : Eq) (M : Map.S) : Eq with type a = E.a M.t
+module Eq_set_s_t (S : Set.S) : Eq with type a = S.t
diff --git a/lib/deriving_interned.ml b/lib/deriving_interned.ml
index 202495b..d53bcc7 100644
--- a/lib/deriving_interned.ml
+++ b/lib/deriving_interned.ml
@@ -4,25 +4,25 @@
 *)
 
 (* Interned strings *)
-module StringMap = Map.Make(String)
+module BytesMap = Map.Make(Bytes)
 
 (* global state *)
-let map = ref StringMap.empty
+let map = ref BytesMap.empty
 let counter = ref 0
 
 type t = int * string
     deriving (Show)
 
-let intern s = 
-  try StringMap.find s !map
+let intern s =
+  try BytesMap.find s !map
   with Not_found ->
-    let fresh = (!counter, String.copy s) in begin
-        map := StringMap.add s fresh !map;
-        incr counter;
-        fresh
-      end
-        
-let to_string (_,s) = String.copy s
+    let fresh = (!counter, Bytes.of_string s) in begin
+      map := BytesMap.add s fresh !map;
+      incr counter;
+      fresh
+    end
+
+let to_string (_,s) = Bytes.to_string s
 let name = snd
 let compare (l,_) (r,_) = compare l r
 let eq (l,_) (r,_) = l = r
diff --git a/myocamlbuild.ml b/myocamlbuild.ml
index a0d4791..0b3a295 100644
--- a/myocamlbuild.ml
+++ b/myocamlbuild.ml
@@ -27,4 +27,45 @@ let _ =
                 flag ["ocaml"; "doc"; tag] & S[A"-ppopt"; A file];
                 dep ["ocaml"; "ocamldep"; tag] [file])
              ["common"; "std"; "tc"; "classes"];
+
+           (* Use an introduction page with categories *)
+           tag_file "deriving-api.docdir/index.html" ["apiref"];
+           dep ["apiref"] ["doc/apiref-intro"];
+           flag ["apiref"] & S[A "-intro"; P "doc/apiref-intro"; A"-colorize-code"];
+
        | _ -> ())
+
+
+
+(* Compile the wiki version of the Ocamldoc.
+
+   Thanks to Till Varoquaux on usenet:
+   http://www.digipedia.pl/usenet/thread/14273/231/
+
+*)
+
+let ocamldoc_wiki tags deps docout docdir =
+  let tags = tags -- "extension:html" in
+  Ocamlbuild_pack.Ocaml_tools.ocamldoc_l_dir tags deps docout docdir
+
+let () =
+  try
+    let wikidoc_dir =
+      let base = Ocamlbuild_pack.My_unix.run_and_read "ocamlfind query wikidoc" in
+      String.sub base 0 (String.length base - 1)
+    in
+
+    Ocamlbuild_pack.Rule.rule
+      "ocamldoc: document ocaml project odocl & *odoc -> wikidocdir"
+      ~insert:`top
+      ~prod:"%.wikidocdir/index.wiki"
+      ~stamp:"%.wikidocdir/wiki.stamp"
+      ~dep:"%.odocl"
+      (Ocamlbuild_pack.Ocaml_tools.document_ocaml_project
+         ~ocamldoc:ocamldoc_wiki
+         "%.odocl" "%.wikidocdir/index.wiki" "%.wikidocdir");
+
+    tag_file "deriving-api.wikidocdir/index.wiki" ["apiref";"wikidoc"];
+    flag ["wikidoc"] & S[A"-i";A wikidoc_dir;A"-g";A"odoc_wiki.cma"]
+
+  with Failure e -> () (* Silently fail if the package wikidoc isn't available *)
diff --git a/opam b/opam
new file mode 100644
index 0000000..bf200f3
--- /dev/null
+++ b/opam
@@ -0,0 +1,26 @@
+opam-version: "1.2"
+name: "deriving"
+version: "dev"
+maintainer: "dev at ocsigen.org"
+homepage: "http://ocsigen.org/deriving/"
+bug-reports: "https://github.com/ocsigen/deriving/issues/"
+license: "MIT"
+build: [
+  [ "./configure" "--prefix" prefix "--%{type_conv:enable}%-tc" ]
+  [ make ]
+]
+install: [ make "install" ]
+remove: [ "ocamlfind" "remove" "deriving" ]
+depends: [
+  "ocamlfind"
+  "camlp4"
+  "optcomp"
+  ## OASIS is not required in released version
+  "oasis" {>= "0.4.4"}
+]
+depopts: [
+  "type_conv"
+]
+conflicts: [
+  "type_conv" {< "108.07.00"}
+]
diff --git a/opam/descr b/opam/descr
deleted file mode 100644
index cf0194e..0000000
--- a/opam/descr
+++ /dev/null
@@ -1 +0,0 @@
-Extension to OCaml for deriving functions from type declarations
\ No newline at end of file
diff --git a/opam/opam b/opam/opam
deleted file mode 100644
index 2246b39..0000000
--- a/opam/opam
+++ /dev/null
@@ -1,16 +0,0 @@
-opam-version: "1"
-maintainer: "gregoire.henry at inria.fr"
-build: [
-  ["%{make}%"]
-  ["%{make}%" "install"]
-]
-remove: [
-  ["ocamlfind" "remove" "deriving"]
-]
-depends: [
-  "ocamlfind"
-  "optcomp"
-]
-depopts: [
-  "type_conv" {>= "108.07.00"}
-]
diff --git a/opam/url b/opam/url
deleted file mode 100644
index 9b11fd4..0000000
--- a/opam/url
+++ /dev/null
@@ -1 +0,0 @@
-git: "https://github.com/ocsigen/deriving.git"
diff --git a/setup.ml b/setup.ml
index db1ceef..099df74 100644
--- a/setup.ml
+++ b/setup.ml
@@ -1,6 +1,6 @@
 
 (* OASIS_START *)
-(* DO NOT EDIT (digest: 9852805d5c19ca1cb6abefde2dcea323) *)
+(* DO NOT EDIT (digest: 172e37fc4b327922311f6cf9389bc560) *)
 (******************************************************************************)
 (* OASIS: architecture for building OCaml libraries and applications          *)
 (*                                                                            *)
@@ -23,14 +23,7 @@
 (* Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA              *)
 (******************************************************************************)
 
-let () =
-  try
-    Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
-  with Not_found -> ()
-;;
-#use "topfind";;
-#require "oasis.dynrun";;
-open OASISDynRun;;
+open OASISDynRun
 
 (* OASIS_STOP *)
 
diff --git a/syntax/common/extend.ml b/syntax/common/extend.ml
index e05b85b..835c3e7 100644
--- a/syntax/common/extend.ml
+++ b/syntax/common/extend.ml
@@ -32,12 +32,46 @@ module Deriving (S : Camlp4.Sig.Camlp4Syntax) = struct
 
   include Syntax
 
+  let rec drop n l =
+     if n <= 0 then
+       l
+     else
+       match l with
+       | [] -> []
+       | _ :: l -> drop (n - 1) l
+
+  let test_val_longident_dot_lt =
+    Gram.Entry.of_parser "test_val_longident_dot_lt" (fun strm ->
+      let rec test_longident_dot pos tokens =
+        match tokens with
+        | (ANTIQUOT ((""|"id"|"anti"|"list"), _), _) :: tokens ->
+          test_longident_dot (pos+1) tokens
+        | (UIDENT _, _) :: (KEYWORD ".", _) :: (LIDENT _, _) :: tokens ->
+          test_longident_dot (pos+3) tokens
+        | _ :: _ ->
+          test_delim pos tokens
+        | [] -> fetch_more test_longident_dot pos
+      and test_delim pos tokens =
+        if pos = 0 then
+          raise Stream.Failure
+        else
+          match tokens with
+          | (KEYWORD ("<"), _) :: _ -> ()
+          | _ :: _ -> raise Stream.Failure
+          | [] -> fetch_more test_delim pos
+      and fetch_more k pos =
+        match drop pos (Stream.npeek (pos + 10) strm) with
+        | [] -> raise Stream.Failure
+        | tokens -> k pos tokens
+      in fetch_more test_longident_dot 0
+    )
+
   open Ast
 
   EXTEND Gram
   expr: LEVEL "simple"
   [
-  [ TRY [e1 = val_longident ; "<" ; t = ctyp; ">" ->
+  [ TRY[ test_val_longident_dot_lt; e1 = val_longident ; "<" ; t = ctyp; ">" ->
      match e1 with
        | <:ident< $uid:classname$ . $lid:methodname$ >> ->
 	   let m = instantiate _loc t classname in
@@ -50,7 +84,7 @@ module Deriving (S : Camlp4.Sig.Camlp4Syntax) = struct
 
   module_expr: LEVEL "simple"
   [
-  [ TRY [e1 = val_longident ; "<" ; t = ctyp; ">" ->
+  [ TRY[ test_val_longident_dot_lt; e1 = val_longident ; "<" ; t = ctyp; ">" ->
      match e1 with
        | <:ident< $uid:classname$ >> ->
 	   instantiate _loc t classname
diff --git a/syntax/common/utils.ml b/syntax/common/utils.ml
index f008c30..67f88e0 100644
--- a/syntax/common/utils.ml
+++ b/syntax/common/utils.ml
@@ -146,6 +146,11 @@ struct
     | TyAnP _ -> "TyAnP"
     | TyAnM _ -> "TyAnM"
 #endif
+#if ocaml_version >= (4, 02)
+    | TyAtt (_,name,_,c) -> "TyAtt("^ name ^", "^ ctyp c ^")"
+    | TyExt (_,name,args,c) -> "TyExt("^ ident name ^", ["^ (String.concat ", " (List.map ctyp args)) ^ "], " ^ ctyp c ^")"
+    | TyOpn _ -> "TyOpn"
+#endif
 end
 
 module Map = struct
@@ -207,9 +212,9 @@ end
 let random_id length =
   let idchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'" in
   let nidchars = String.length idchars in
-  let s = String.create length in
+  let s = Bytes.create length in
     for i = 0 to length - 1 do
-      s.[i] <- idchars.[Random.int nidchars]
+      Bytes.set s i idchars.[Random.int nidchars]
     done;
     s
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/ocaml-deriving-ocsigen.git



More information about the Pkg-ocaml-maint-commits mailing list