* [Caml-list] concerning using of `deriving' syntactic plugin @ 2012-03-07 11:49 Matej Košík 2012-03-07 12:31 ` Gabriel Scherer 2012-03-07 12:34 ` Yaron Minsky 0 siblings, 2 replies; 10+ messages in thread From: Matej Košík @ 2012-03-07 11:49 UTC (permalink / raw) To: Caml List Hi, I would like to print out the response of a modified Ocaml's typechecker to various inputs. One way to do it would be to write a pretty-printer by hand. Before I do that, I would like to apply "deriving" machinery: http://code.google.com/p/deriving/wiki/Introduction to this (chore) job. In some cases I do not know what to do. E.g., file "types/types.mli" contains the following definition: and value_kind = Val_reg | Val_prim of Primitive.description | Val_ivar of mutable_flag * string | Val_self of (Ident.t * type_expr) Meths.t ref * (Ident.t * mutable_flag * virtual_flag * type_expr) Vars.t ref * string * type_expr | Val_anc of (string * Ident.t) list * string | Val_unbound If I add deriving (Show) at the end of the above definition, I get an error: Error: Unbound module Meths.Show_t That is expected but I am not sure what to do. That is, I am not sure what is the official way to "deriving"-sify the "Meth" module which defined in the following way: module Meths = Map.Make(OrderedString) without the need to modify files "map.ml{i,}". Is something like that possible? Thank you very much in advance for any help. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] concerning using of `deriving' syntactic plugin 2012-03-07 11:49 [Caml-list] concerning using of `deriving' syntactic plugin Matej Košík @ 2012-03-07 12:31 ` Gabriel Scherer 2012-03-07 16:44 ` Matej Košík 2012-03-07 12:34 ` Yaron Minsky 1 sibling, 1 reply; 10+ messages in thread From: Gabriel Scherer @ 2012-03-07 12:31 UTC (permalink / raw) To: Matej Košík; +Cc: Caml List You can inject the definition you want in the following way: module Meths = struct include Meths module Show_t = ... end type value_kind = ... deriving (Show) This works because deriving, being a Camlp4 extension, does not refer to "the" module Meths, but any module Meths that is in scope at the place of expansion. This could be seen as a defect of hygiene (indeed that makes camlp4 macro non-hygienic according to the Scheme notion of hygiene) but is also a feature, rather than a bug, of the syntactic macro system; because as a macro-writer you can give flexibility to the user by specifying the free variables you rely on. On Wed, Mar 7, 2012 at 12:49 PM, Matej Košík <5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote: > Hi, > > I would like to print out the response of a modified Ocaml's typechecker > to various inputs. > > One way to do it would be to write a pretty-printer by hand. > > Before I do that, I would like to apply "deriving" machinery: > http://code.google.com/p/deriving/wiki/Introduction > to this (chore) job. > > In some cases I do not know what to do. > > E.g., file "types/types.mli" contains the following definition: > > and value_kind = > Val_reg > | Val_prim of Primitive.description > | Val_ivar of mutable_flag * string > | Val_self of > (Ident.t * type_expr) Meths.t ref * > (Ident.t * mutable_flag * virtual_flag * type_expr) Vars.t ref * > string * type_expr > | Val_anc of (string * Ident.t) list * string > | Val_unbound > > If I add > > deriving (Show) > > at the end of the above definition, I get an error: > > Error: Unbound module Meths.Show_t > > That is expected but I am not sure what to do. That is, I am not sure > what is the official way to "deriving"-sify the "Meth" module which > defined in the following way: > > module Meths = Map.Make(OrderedString) > > without the need to modify files "map.ml{i,}". > > Is something like that possible? > > Thank you very much in advance for any help. > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] concerning using of `deriving' syntactic plugin 2012-03-07 12:31 ` Gabriel Scherer @ 2012-03-07 16:44 ` Matej Košík 2012-03-07 17:06 ` Jérémie Dimino 0 siblings, 1 reply; 10+ messages in thread From: Matej Košík @ 2012-03-07 16:44 UTC (permalink / raw) To: Gabriel Scherer; +Cc: Caml List On 03/07/2012 12:31 PM, Gabriel Scherer wrote: > You can inject the definition you want in the following way: > > module Meths = struct > include Meths > module Show_t = ... > end > > type value_kind = ... > deriving (Show) > > This works because deriving, being a Camlp4 extension, does not refer > to "the" module Meths, but any module Meths that is in scope at the > place of expansion. This could be seen as a defect of hygiene (indeed > that makes camlp4 macro non-hygienic according to the Scheme notion of > hygiene) but is also a feature, rather than a bug, of the syntactic > macro system; because as a macro-writer you can give flexibility to > the user by specifying the free variables you rely on. I have never used "include" construct myself but I always wanted it. Its cool that we have it :-) The above problem can indeed be solved, i.e. pretty-printer can be generated in this way. The tricky part is to figure out how to define the "Show_t" module definition, which is non-obvious. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] concerning using of `deriving' syntactic plugin 2012-03-07 16:44 ` Matej Košík @ 2012-03-07 17:06 ` Jérémie Dimino 0 siblings, 0 replies; 10+ messages in thread From: Jérémie Dimino @ 2012-03-07 17:06 UTC (permalink / raw) To: Matej Košík; +Cc: Caml List Le Wed, 07 Mar 2012 16:44:20 +0000, Matej Košík <5764c029b688c1c0d24a2e97cd764f@gmail.com> a écrit : > The above problem can indeed be solved, i.e. pretty-printer can be > generated in this way. The tricky part is to figure out how to define > the "Show_t" module definition, which is non-obvious. If you can modify the definition of Meths the easiest way is: module Meths = struct include Map.Make(OrderedString) module Show_t = Show.Show_map(OrderedString)(Show.Show_string) end -- Jérémie ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] concerning using of `deriving' syntactic plugin 2012-03-07 11:49 [Caml-list] concerning using of `deriving' syntactic plugin Matej Košík 2012-03-07 12:31 ` Gabriel Scherer @ 2012-03-07 12:34 ` Yaron Minsky 2012-03-07 16:44 ` Matej Košík 1 sibling, 1 reply; 10+ messages in thread From: Yaron Minsky @ 2012-03-07 12:34 UTC (permalink / raw) To: Matej Košík; +Cc: Caml List [-- Attachment #1: Type: text/plain, Size: 2288 bytes --] Are you familiar with type-conv and the family of syntax-extensions that go along with it? You can do thinks like: type t = { foo: int; bar: string } with sexp, compare, bin_io and automatically get sexp-conversion functions, a comparison function, and binary protocol converters. And type-conv has been used to build other type-directed functions by other people outside of Jane Street. The latest version is available on bitbucket, and we'll have a new blessed release in a few days. https://bitbucket.org/yminsky/ocaml-core/ Note that this is done purely syntactically, and yet gets you there. y On Wed, Mar 7, 2012 at 6:49 AM, Matej Košík < 5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote: > Hi, > > I would like to print out the response of a modified Ocaml's typechecker > to various inputs. > > One way to do it would be to write a pretty-printer by hand. > > Before I do that, I would like to apply "deriving" machinery: > http://code.google.com/p/deriving/wiki/Introduction > to this (chore) job. > > In some cases I do not know what to do. > > E.g., file "types/types.mli" contains the following definition: > > and value_kind = > Val_reg > | Val_prim of Primitive.description > | Val_ivar of mutable_flag * string > | Val_self of > (Ident.t * type_expr) Meths.t ref * > (Ident.t * mutable_flag * virtual_flag * type_expr) Vars.t ref * > string * type_expr > | Val_anc of (string * Ident.t) list * string > | Val_unbound > > If I add > > deriving (Show) > > at the end of the above definition, I get an error: > > Error: Unbound module Meths.Show_t > > That is expected but I am not sure what to do. That is, I am not sure > what is the official way to "deriving"-sify the "Meth" module which > defined in the following way: > > module Meths = Map.Make(OrderedString) > > without the need to modify files "map.ml{i,}". > > Is something like that possible? > > Thank you very much in advance for any help. > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > [-- Attachment #2: Type: text/html, Size: 3622 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] concerning using of `deriving' syntactic plugin 2012-03-07 12:34 ` Yaron Minsky @ 2012-03-07 16:44 ` Matej Košík 2012-03-07 17:10 ` Markus Mottl 0 siblings, 1 reply; 10+ messages in thread From: Matej Košík @ 2012-03-07 16:44 UTC (permalink / raw) To: Yaron Minsky; +Cc: Caml List On 03/07/2012 12:34 PM, Yaron Minsky wrote: > Are you familiar with type-conv and the family of syntax-extensions that > go along with it? You can do thinks like: > > type t = { foo: int; bar: string } > with sexp, compare, bin_io > > > and automatically get sexp-conversion functions, a comparison function, > and binary protocol converters. And type-conv has been used to build > other type-directed functions by other people outside of Jane Street. > > The latest version is available on bitbucket, and we'll have a new > blessed release in a few days. > > https://bitbucket.org/yminsky/ocaml-core/ > > > Note that this is done purely syntactically, and yet gets you there. I have looked at bin_prot and sexplib previously. They are very nice and useful. I have found one (I guess unnecessary) disadvantage over `deriving'. If you process your *.ml file with sexplib/bin_prot preprocessor, you have to append "with ..." suffix to every type definition, otherwise you will get a an error report from the preprocessor. `Deriving' does not force you to do that. You can annotate only those type definitions, which for you makes sense to annotate. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] concerning using of `deriving' syntactic plugin 2012-03-07 16:44 ` Matej Košík @ 2012-03-07 17:10 ` Markus Mottl 2012-03-07 17:28 ` Matej Košík 0 siblings, 1 reply; 10+ messages in thread From: Markus Mottl @ 2012-03-07 17:10 UTC (permalink / raw) To: Matej Košík; +Cc: Yaron Minsky, Caml List On Wed, Mar 7, 2012 at 11:44, Matej Košík <5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote: > I have found one (I guess unnecessary) disadvantage over `deriving'. > If you process your *.ml file with sexplib/bin_prot preprocessor, you > have to append "with ..." suffix to every type definition, otherwise you > will get a an error report from the preprocessor. `Deriving' does not > force you to do that. You can annotate only those type definitions, > which for you makes sense to annotate. I'm not sure what the perceived problem is, but there should be no need to annotate all type definitions. It should suffice to annotate those for which converters are needed. This, of course, means that any types that a type definition is referring to will also need annotations (or hand-written conversion functions). Regards, Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] concerning using of `deriving' syntactic plugin 2012-03-07 17:10 ` Markus Mottl @ 2012-03-07 17:28 ` Matej Košík 2012-03-07 20:47 ` Till Varoquaux 2012-03-08 2:49 ` Markus Mottl 0 siblings, 2 replies; 10+ messages in thread From: Matej Košík @ 2012-03-07 17:28 UTC (permalink / raw) To: Markus Mottl, Yaron Minsky; +Cc: Caml List Hi Markus, On 03/07/2012 05:10 PM, Markus Mottl wrote: > On Wed, Mar 7, 2012 at 11:44, Matej Košík > <5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote: >> I have found one (I guess unnecessary) disadvantage over `deriving'. >> If you process your *.ml file with sexplib/bin_prot preprocessor, you >> have to append "with ..." suffix to every type definition, otherwise you >> will get a an error report from the preprocessor. `Deriving' does not >> force you to do that. You can annotate only those type definitions, >> which for you makes sense to annotate. > > I'm not sure what the perceived problem is, but there should be no > need to annotate all type definitions. It should suffice to annotate > those for which converters are needed. The following artificial example: open Sexplib.Conv type foo = int * int with sexp type bar = float * float with sexp is compilable (e.g.: ocamlc -o main -pp "camlp4of -I /home/mkosik/lib/godi/lib/ocaml/std-lib/../pkg-lib/sexplib -I /home/mkosik/lib/godi/lib/ocaml/std-lib/../pkg-lib/type-conv pa_type_conv.cma pa_sexp_conv.cma" -I /home/mkosik/lib/godi/lib/ocaml/std-lib/../pkg-lib/sexplib -I /home/mkosik/lib/godi/lib/ocaml/std-lib/../pkg-lib/type-conv unix.cma nums.cma bigarray.cma sexplib.cma main.ml ) If you remove any of the "with sexp" clauses, you will get a preprocessor error: File "main.ml", line 4, characters 18-23: Parse error: "with" expected after [type_declaration] (in [str_item]) File "main.ml", line 1, characters 0-1: This is at least what I am experiencing. > This, of course, means that > any types that a type definition is referring to will also need > annotations (or hand-written conversion functions). Regards, Matej Kosik ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] concerning using of `deriving' syntactic plugin 2012-03-07 17:28 ` Matej Košík @ 2012-03-07 20:47 ` Till Varoquaux 2012-03-08 2:49 ` Markus Mottl 1 sibling, 0 replies; 10+ messages in thread From: Till Varoquaux @ 2012-03-07 20:47 UTC (permalink / raw) To: Matej Košík; +Cc: Markus Mottl, Yaron Minsky, Caml List You are the wrong version of camlp4 (the different campl4 binaries load different libraries, syntaxes etc...). If you switch camlp4orf to camlp4o your code should compile fine. Also note that I would recommend using the excellent ocamlfind tool: ocamlfind c -linkpkg -package sexplib,sexplib.syntax -syntax camlp4o main.ml Till On Wed, Mar 7, 2012 at 12:28 PM, Matej Košík <5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote: > Hi Markus, > > On 03/07/2012 05:10 PM, Markus Mottl wrote: >> On Wed, Mar 7, 2012 at 11:44, Matej Košík >> <5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote: >>> I have found one (I guess unnecessary) disadvantage over `deriving'. >>> If you process your *.ml file with sexplib/bin_prot preprocessor, you >>> have to append "with ..." suffix to every type definition, otherwise you >>> will get a an error report from the preprocessor. `Deriving' does not >>> force you to do that. You can annotate only those type definitions, >>> which for you makes sense to annotate. >> >> I'm not sure what the perceived problem is, but there should be no >> need to annotate all type definitions. It should suffice to annotate >> those for which converters are needed. > > The following artificial example: > > open Sexplib.Conv > type foo = int * int with sexp > type bar = float * float with sexp > > is compilable > > (e.g.: > ocamlc -o main -pp "camlp4of -I > /home/mkosik/lib/godi/lib/ocaml/std-lib/../pkg-lib/sexplib -I > /home/mkosik/lib/godi/lib/ocaml/std-lib/../pkg-lib/type-conv > pa_type_conv.cma pa_sexp_conv.cma" -I > /home/mkosik/lib/godi/lib/ocaml/std-lib/../pkg-lib/sexplib -I > /home/mkosik/lib/godi/lib/ocaml/std-lib/../pkg-lib/type-conv unix.cma > nums.cma bigarray.cma sexplib.cma main.ml > ) > > If you remove any of the "with sexp" clauses, you will get a > preprocessor error: > > File "main.ml", line 4, characters 18-23: > Parse error: "with" expected after [type_declaration] (in [str_item]) > File "main.ml", line 1, characters 0-1: > > This is at least what I am experiencing. > >> This, of course, means that >> any types that a type definition is referring to will also need >> annotations (or hand-written conversion functions). > > Regards, > > Matej Kosik > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] concerning using of `deriving' syntactic plugin 2012-03-07 17:28 ` Matej Košík 2012-03-07 20:47 ` Till Varoquaux @ 2012-03-08 2:49 ` Markus Mottl 1 sibling, 0 replies; 10+ messages in thread From: Markus Mottl @ 2012-03-08 2:49 UTC (permalink / raw) To: Matej Košík; +Cc: Yaron Minsky, Caml List On Wed, Mar 7, 2012 at 12:28, Matej Košík <5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote: > If you remove any of the "with sexp" clauses, you will get a > preprocessor error: > > File "main.ml", line 4, characters 18-23: > Parse error: "with" expected after [type_declaration] (in [str_item]) > File "main.ml", line 1, characters 0-1: Till's fix suggestion should work, you'll have to use camlp4o as preprocessor. Btw., you also may want to "open Sexplib.Std" instead of "Sexplib.Conv", which is the "standard" way. Regards, Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2012-03-08 2:49 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-03-07 11:49 [Caml-list] concerning using of `deriving' syntactic plugin Matej Košík 2012-03-07 12:31 ` Gabriel Scherer 2012-03-07 16:44 ` Matej Košík 2012-03-07 17:06 ` Jérémie Dimino 2012-03-07 12:34 ` Yaron Minsky 2012-03-07 16:44 ` Matej Košík 2012-03-07 17:10 ` Markus Mottl 2012-03-07 17:28 ` Matej Košík 2012-03-07 20:47 ` Till Varoquaux 2012-03-08 2:49 ` Markus Mottl
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox