archive-fr.com » FR » N » NICOLASPOUILLARD.FR

Total: 307

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".

  • README module README where import binding representations import nbe terms negative types here import nbe

    Original URL path: http://nicolaspouillard.fr/publis/lfmtp2012-talk/html/README.html (2015-10-11)
    Open archived version from archive


  • Overloading, searching for alternatives
    bool x x true val id bool Bool t Bool t let id float x x 0 0 val id float Float t Float t overload id1 Î Î instance id1 id int id bool overload id2 Î Î instance id2 id float id int fun x id1 id2 x fun Int t Int t Why alternatives must be pairwise not unifiable let inc fst p fst p 1 val inc fst Int t Î Int t let inc snd p snd p 1 val inc snd Î Int t Int t overload inc one Πβ Int t instance inc one inc fst inc snd Attempt to overload inc one with alternatives inc fst Int t Î Int t inc snd β Int t Int t Indeed inc one 42 true and inc one foo 64 make sense but what about inc one 16 64 Overloading and modularity Better distinction since we must give to the candidate a name And then add the candidates to an overloaded symbol Modules like Int Float are concrete A module like Num can declare overloaded symbols Then the user can choose and is not a prisoner of overloading Delegated overloading Delegated overloading One wants to compile such a generic definition let double x x x The solution adopted An overloading error too much candidates becomes an implicit argument when the overloading can be resolved later In a nutshell While classic overloading is just some type directed sugar delegated overloading allows generic programming The outcome of overloading complete Context Are we defining a value called def Is this choice future proof called future proof Outcome if no candidates and future proof then raise an overloading error else if only one candidate and future proof or not def then keep it else if def then abstract over its implementation else raise an overloading error How delegated overloading works Principle When an overloaded symbol cannot be resolved but could be in the future we abstract the current definition from the implementation of unresolved symbols These implicit arguments are then re introduced at each call site as overloaded occurrences Note In this system the resolution strategy is fixed Delegated overloading in action let double x x x val double Î Î Î Î Î In fact the definition of double implicitly becomes let double x x x And a call to the function double is treated like that double 42 â double Î Î Î 42 â double Int t Int t Int t 42 â double Int 42 Implicit arguments For each occurrence Given an overloaded symbol f f a1 t1 aN tN t Add all implicit arguments f x â f t1 tN t a1 aN x Implicit arguments are lexically ordered distinct by name and type others are merged Closing the overloading Prevent a symbol from being extended Is useful from development policy point of view Can help the typing algorithm to pick a candidate Syntax of closing close overload future proof extension We

    Original URL path: http://nicolaspouillard.fr/talks/overloading-searching-for-alternatives.html (2015-10-11)
    Open archived version from archive


  • NomPa Examples BareDB import NomPa Examples Raw import NomPa Examples Raw Parser import NomPa Examples Raw Printer Encodings Emebedding of nominal types import NomPa Encodings NominalTypes import NomPa Encodings NominalTypes Generic import NomPa Encodings NominalTypes Generic Subst import NomPa Encodings NominalTypes Generic Combined import NomPa Encodings NominalTypes MultiSorts import NomPa Encodings NominalTypes MultiSorts Test import NomPa Encodings AlphaCaml import NomPa Encodings AlphaCaml Test import NomPa Encodings BindersUnbound import NomPa Encodings

    Original URL path: https://nicolaspouillard.fr/publis/NomPa.agda/ (2015-10-11)
    Open archived version from archive

  • ocamlbuild, a tool for automatic compilation of OCaml projects
    discover dependencies using ocamldep ocamldep cannot always be trusted backtrack if necessary Launch compilations and discover more dependencies Demo Many projects can be compiled with a single command Menhir ocamlbuild lib unix back native Hevea ocamlbuild latexmain native Ergo ocamlbuild main native Ocamlgraph ocamlbuild cflags for pack Ocamlgraph demo native To be fair Some of these projects require that a version ml or stdlib ml file be generated beforehand Dealing with exceptions to standard rules What s an exception Files that need specific flags Warnings to be enabled or disabled Debugging g profiling p type annotation recursive types linkall thread custom Units that need external C libraries Binaries that need external OCaml libraries Directories that must be included or excluded Dependencies that cannot be discovered Make and exceptions The make tool can t handle exceptions very well Needs exceptions to be encoded as specific rules This generally makes rules and exceptions tightly bound by variables This creates non modular makefiles that don t scale The tags our way to specify exceptions The tags file is made of lines Each line is made of a pattern and a list of signed tags A line adds or removes tags from matching files Patterns are boolean combinations of shell like globbing expressions funny ml rectypes ml warn A warn error A debug dtypes cmx inline 9 foo ml or bar ml warn v warn error v vendor ml warn A warn error A main byte native use unix main byte use dynlink linkall test not hygienic satsolver cm io precious How tags and rules give commands Files are tagged using tagging rules foo bar ml rectypes Rules then produce commands with tagged holes let tagged hole tags for ml ocaml compile byte in Cmd S A ocamlc A c T tagged hole P ml A o P cmo These holes are filled by command fragments such as flags flag ocaml compile byte rectypes A rectypes Tags and dependencies One can define dependencies triggered by combinations of tags dep ocaml link byte program plugin foo plugin pluginlib cma plugin plugin foo cmo By tagging files we make things happen test byte plugin foo Writing an ocamlbuild plugin Not a specific language but plain OCaml code Plugins are compiled on the fly Dynamic configuration is feasible With a plugin one can Extend rules add new ones override old ones Add flags and dependencies based on tags Tag files Change options Define the directory structure precisely Help ocamldep Specify external libraries A plugin example Let s read it in live General features Parallel execution where applicable You select the maximum number of jobs j N Rules know how to ask for parallel targets The system keeps things scheduled correctly Example Separate compilation of byte code Optimal scheduling would require a static graph A status bar for your visual comfort Compilation tools echo commands and their output This creates a long and boring output that scrolls too fast Here you can keep an eye on what is

    Original URL path: http://nicolaspouillard.fr/ocamlbuild/ocamlbuild-presentation.html (2015-10-11)
    Open archived version from archive

  • The ocamlbuild users manual
    01 17 16 23 hello ml rw rw 1 linus gallium 17 2007 01 17 16 24 hello ml depends rwxrwx 1 linus gallium 173528 2007 01 17 16 24 hello native rw rw 1 linus gallium 936 2007 01 17 16 24 hello o rw rw 1 linus gallium 22 2007 01 17 16 24 ocamlc where 3 3 Executing my code You can execute your code the old fashioned way hello native You may also type ocamlbuild hello native Caesar and it will compile and then run hello native with the arguments following which should display ocamlbuild hello native Caesar Finished 4 targets 0 cached in 00 00 00 Hello Caesar My name is build hello native 3 4 The log file verbosity and debugging By default if you run ocamlbuild on a terminal it will use some ANSI escape sequences to display a nice one line progress indicator To see what commands ocamlbuild has actually run you can check the contents of the log file To change the name of the log file or to disable logging use the log file or no log options Note that the log file is truncated at each execution of ocamlbuild The log file contains all the external commands that ocamlbuild ran or intended to run along with the target name and the computed tags With the verbose level option ocamlbuild will also write more or less useful debugging information a verbosity level of 1 which can also be specified using the verbose switch prints generally useful information higher levels produce much more output 3 5 Cleaning ocamlbuild may leave a build directory symbolic links to executables in that directory and a log file All of these can be removed safely by hand or by invoking ocamlbuild with the clean flag 3 6 Where and how to run ocamlbuild An important point is that ocamlbuild must be invoked from the root of the project even if this project has multiple nested subdirectories This is because ocamlbuild likes to store the object files in a single build directory You can change the name of that directory with the build dir option ocamlbuild can be either invoked manually from the UNIX or Windows shell or automatically from a build script or a Makefile Unless run with the no hygiene option there is the possibility that ocamlbuild will prompt the user for a response By default on UNIX systems if ocamlbuild senses that the standard output is a terminal it will use a nice progress indicator using ANSI codes instrumenting the output of the processes it spawns to have a consistent display Under non UNIX systems or if the standard output is not a terminal it will run in classic mode where it will echo the executed commands on its standard output This selection can be overridden with the classic display option 3 7 Dependencies Dependencies are automatically discovered Most of the value of ocamlbuild lies in the fact that it often needs no extra information to compile a project besides the name of the top level module ocamlbuild calls ocamldep to automatically find the dependencies of any modules it wants to compile These dependencies are dynamically incorporated in the dependency graph something make cannot do For instance let s add a module Greet that implements various ways of greeting people cat greet ml type how Nicely Badly let greet how who match how with Nicely Printf printf Hello s n who Badly Printf printf Oh here is that s again n who cat hello ml open Greet let let name if Array length Sys argv 1 then Sys argv 1 else stranger in greet if name Caesar then Nicely else Badly name Printf printf My name is s n Sys argv 0 Then the module Hello depends on the module Greet and ocamlbuild can figure this out for himself we still only have to invoke ocamlbuild hello native Needless to say this works for any number of modules 3 8 Native and byte code If we want to compile byte code instead of native we just a target name of hello byte instead of hello native i e we type ocamlbuild hello byte 3 9 Compile flags To pass a flag to the compiler such as the rectypes option use the cflag option as in ocamlbuild cflag rectypes hello native You can put multiple cflag options they will be passed to the compiler in the same order You can also given them in a comma separated list with the cflags option notice the plural ocamlbuild cflags I lablgtk rectypes hello native These flags apply when compiling that is when producing cmi cmo cmx and o files from ml or mli files 3 10 Link flags Link flags apply when the various object files are collected and linked into one executable These will typically be include directories for libraries They are given using the lflag and lflags options which work in the same way as the cflag and cflags options 3 11 Linking with external libraries In our third example we use one Unix system call and functions from the num library cat epoch ml let let s Num num of string Printf sprintf 0f Unix gettimeofday in let ps Num mult num Num num of string 1000000000000 s in Printf printf s picoseconds have passed since January 1st 1970 n Num string of num ps This requires linking with the unix and num modules which is accomplished by using the lib unix and lib num flags or alternatively libs unix num ocamlbuild libs nums unix epoch native Finished 4 targets 4 cached in 00 00 00 1169051647000000000000 picoseconds have passed since January 1st 1970 You may need to add options such as cflags I usr local lib ocaml and lflags I usr local lib ocaml if the libraries you wish to link with are not in OCaml s default search path 3 12 The tags files Finer control over the compiler flags applied to each source file such as preprocessing debugging profiling and linking options can be gained using ocamlbuild s tagging mechanism Every source file has a set of tags which tells ocamlbuild what kind of file it is and what to do with it A tag is simply a string usually lowercase for example ocaml or native The set of tags attached to a file is computed by applying the tagging rules to the filename Tagging rules are defined in tags files in any parent directory of a file up to the main project directory Each line in the tags file is made of a glob pattern see subsection 3 13 and a list of tags More than one rule can apply to a file and rules are applied in the order in which they appear in a file By preceding a tag with a minus sign one may remove tags from one or more files 3 12 1 Example the built in tags file ml or mli or mlpack or ml depends ocaml byte ocaml byte program odoc ocaml doc native ocaml native program cma ocaml byte library cmxa ocaml native library cmo ocaml byte cmi ocaml byte native cmx ocaml native A special tag made from the path name of the file relative to the toplevel of the project is automatically defined for each file For a file foo bar ml this tag will be file foo bar ml If you do not have subdirectories you can put ml instead of ml 3 13 Glob patterns and expressions Glob patterns have a syntax similar to those used by UNIX shells to select path names like foo ba They are used in ocamlbuild to define the files and directories to which tags apply Glob expressions are glob patterns enclosed in brackets and combined using the standard boolean operators and or not This allows one to describe sets of path names in more concise and more readable ways Please note that file and directory names are supposed to be made of the following characters a z A Z 0 9 and This is called the pathname alphabet P Formal syntax Example Matches Does not match Meaning formal meaning u A string of pathname characters foo ml foo ml fo ml bar foo ml The exact string u u where u P The wild card star foo bar foo bar bar Any string not containing a slash P The joker a b z bar Any one letter string excluding the slash The prefix inter directory star foo ml foo ml bar foo ml bar baz foo ml foo bar bar The empty string or any string ending with a slash P The suffix inter directory star foo foo foo bar bar foo Any string starting with a slash or the empty string P The infix inter directory star bar foo ml bar foo ml bar baz foo ml foo ml Any string starting and ending with a slash P r 1 r 2 r k where r i is either c or c 1 c 2 1 i k The positive character class a fA F0 9 3 F z bar Any one letter string made of characters from one of the ranges r i 1 i n L r 1 L r n r 1 r 2 r k where r i is either c or c 1 c 2 1 i k The negative character class a fA F0 9 z bar 3 F Any one letter string NOT made of characters from one of the ranges r i 1 i n L r 1 L r n p 1 p 2 A concatenation of patterns foo foo foob foobar fo bar Any string with a prefix matching p 1 and the corresponding suffix matching p 2 uv u L p 1 v L p 2 p 1 p 2 p k A union of patterns toto ml mli toto ml toto mli toto Any string matching one of the patterns p i for 1 i k L p 1 L p k Table 1 Syntax and semantics of glob patterns Formal syntax Example Meaning formal meaning p foo ml Pathnames matching the pattern p e 1 or e 2 ml or foo bar ml Pathnames matching at least one of the expressions e 1 and e 2 e 1 and e 2 ml and foo Pathnames matching both expressions e 1 and e 2 not e not mli Pathnames not matching the expression e true true All pathnames false false No pathnames Table 2 Syntax and semantics of glob expressions 3 14 Subdirectories If the files of your project are held in one or more subdirectories ocamlbuild must be made aware of that fact using the I or Is options or by adding an include tag For instance assume your project is made of three subdirectories foo bar and baz containing various ml files the main file being foo main ml Then you can either type ocamlbuild Is foo bar baz foo main native or add the following line in the tags file foo or bar or baz include and call ocamlbuild foo main native There are then two cases If no other modules named Bar or Baz exist elsewhere in the project then you are done Just use Foo Foo Bar and Foo Baz in your code Otherwise you will need to use the plugin mechanism and define the mutual visibility of the subdirectories using the Pathname define context function 3 15 Grouping targets with itarget You can create a file named foo itarget containing a list of targets one per line such as main native main byte stuff docdir index html Requesting the target foo otarget will then build every target listed in the file foo itarget Blank lines and dashes to comment out lines are accepted 3 16 Packing subdirectories into modules OCaml s pack option allows you to structure the contents of a module in a subdirectory For instance assume you have a directory foo containing two modules bar ml and baz ml You want from these to build a module Foo containing Bar and Baz as submodules In the case where no modules named Bar or Baz exist outside of Foo To do this you must write a file foo mlpack preferably sitting in the same directory as the directory Foo and containing the list of modules one per line it must contain Bar Baz 3 17 Preprocessor options and tags You can specify preprocessor options with pp followed by the preprocessor string for instance ocamlbuild pp camlp4o opt unsafe would run your sources thru CamlP4 with the unsafe option Another way is to use the tags file Tag Preprocessor command Remark pp cmd cmd Arbitrary preprocessor command 1 camlp4o camlp4o Original OCaml syntax camlp4r camlp4r Revised OCaml syntax camlp4of camlp4of Original OCaml syntax with extensions camlp4rf camlp4rf Revised OCaml syntax with extensions 3 18 Debugging byte code and profiling native code The preferred way of compiling code suitable for debugging with ocamldebug or profiling native code with ocamlprof is to use the appropriate target extensions d byte for debugging or p native Another way is to add use the debug or profile tags Note that these tags must be applied at the compilation and linking stages Hence you must either use tag debug or tag profile on the command line or add a true debug line to your tags file Please note that the byte code profiler works in a wholly different way and is not supported by ocamlbuild 3 19 Generating documentation using ocamldoc Write the names of the modules whose interfaces will be documented in a file whose extension is odocl for example foo odocl then invoke ocamlbuild on the target foo docdir index html This will collect all the documentation from the interfaces which will be build if necessary using ocamldoc and generate a set of HTML files under the directory foo docdir which is actually a link to build foo docdir As for packing subdirectories into modules the module names must be written one per line without extensions and correctly capitalized Note that generating documentation in formats other than HTML or from implementations is not supported 3 20 The display line Provided ocamlbuild runs in a terminal under a POSIX environment it will display a sophisticated progress indicator line that graciously interacts with the output of subcommands This line looks like this 00 00 02 210 180 main cmx ONbp il Here 00 00 02 is the elapsed time in hour minute second format since ocamlbuild has been invoked 210 is the number of external commands typically calls to the compiler or the like that may or may not have been invoked 180 is the number of external commands that have not been invoked since their result is already in the build directory main cmx is the name of the last target built ONbp il is a short string that describes the tags that have been encountered and the slash at the end is a frame from a rotating ticker Hence the display line has the following structure HH MM SS JOBS CACHED PATHNAME TAGS TICKER The tag string is made of 8 indicators which each monitor a tag These tags are ocaml native byte program pp debug interf and link Initially each indicator displays a dash If the current target has the monitored tag then the indicator displays the corresponding character see table 3 in uppercase Otherwise it displays that character in lowercase This allows you to see the set of tags that have been applied to files in your project during the current invocation of ocamlbuild Hence the tag string ONbp il means that the current target main cmx has the tags ocaml and native and that the tags ocaml native byte program interf and link have already been seen Tag Display character ocaml O native N byte B program P pp R debug D interf I link L Table 3 Relation between the characters displayed in the tag string and the tags 3 21 ocamllex ocamlyacc and menhir ocamlbuild knows how to run the standard lexer and parser generator tools ocamllex and ocamlyacc when your files have the standard mll and mly extensions If you want to use menhir instead of ocamlyacc you can either launch ocamlbuild with the use menhir option or add a true use menhir line to your tags file Note that there is currently no way of using menhir and ocamlyacc in the same execution of ocamlbuild 3 22 Changing the compilers or tools As ocamlbuild is part of your OCaml distribution it knows if it can call the native compilers and tools ocamlc opt ocamlopt opt or not However you may want ocamlbuild to use another ocaml compiler for different reasons such as cross compiling or using a wrapper such as ocamlfind Here is the list of relevant options ocamlc command ocamlopt command ocamldep command ocamlyacc command menhir command ocamllex command ocamlmktop command ocamlrun command 3 23 Writing a myocamlbuild ml plugin 3 24 Interaction with version control systems Here are tips for configuring your version control system to ignore the files and directories generated by ocamlbuild The directory build the file log and any symbolic links pointing into build should be ignored To do this you must add the following ignore patterns to your version control system s ignore set log build native byte d native p byte For CVS add the above lines to the cvsignore file For Subversion SVN type svn propedit svn ignore and add the above lines 3 25 A shell script for driving it all To shell or to make Traditionally makefiles have two major functions The first one is the dependency ordering rule matching logic used for compiling The second one is as a dispatcher for various actions defined using phony targets with shell script actions These actions include cleaning cleaning really well archiving

    Original URL path: http://nicolaspouillard.fr/ocamlbuild/ocamlbuild-user-guide.html (2015-10-11)
    Open archived version from archive

  • Myocamlbuild.main
    ldots tag file foo dir not hygienic c One can also do things after the hygiene step After hygiene c One can setup rules before the standard ones but that s not recommended Before rules c Here one can add or override new rules After rules c Rules can be declared by a call of the form rule name prod dep action The first argument is the name of the rule prod string specifies the product of the rule Note that prods string list also exists dep and deps are for dependencies rule LaTeX to PDF conversion rule prod pdf dep tex begin fun env build c The action is a function that receive two arguments env is a conversion function that substitutes occurrences according to the targets to which the rule applies build can be called to build new things dynamic dependencies let tex env tex and pdf env pdf in c Here we say We compile the file tex form LaTeX xspace to PDF Note that in fact that is a set of tags thus the order does not matter But you got the idea let tags tags of pathname tex compile LaTeX pdf in c Here we produce the command to run S is for giving a sequence of command pieces A is for atoms P is for pathnames Px is a special pathname that should be the main product of the rule for display purposes T is for tags The other constructors are given in the documentation of the Command module in Signatures COMMAND let cmd Cmd S pdflatex T tags P tex Sh dev null in c Hoping that LaTeX will converge in two iterations Seq cmd cmd end c Here we make an extension of any rule that produces a command containing these tags

    Original URL path: http://nicolaspouillard.fr/ocamlbuild/plugin_example.html (2015-10-11)
    Open archived version from archive

  • Signatures
    type STRING sig end module type TAGS sig end module type PATHNAME sig end module type COMMAND sig end Provides an abstract type for easily building complex shell commands without making quotation mistakes module type GLOB sig end A self contained module implementing extended shell glob patterns who have an expressive power equal to boolean combinations of regular expressions module type LOG sig end Module for modulating the logging output

    Original URL path: http://nicolaspouillard.fr/ocamlbuild/html/Signatures.html (2015-10-11)
    Open archived version from archive


  • for easily building complex shell commands without making quotation mistakes Configuration Handles the tags file mechanism Discard printf This module compiled with rectypes allows one to write functions taking formatters as arguments Flags For system use only Hygiene Module for checking that the source tree is not polluted by object files Options Pathname Report Resource Rule copy rule name insert source destination Slurp Scans a directory lazily to build a

    Original URL path: http://nicolaspouillard.fr/ocamlbuild/html/index.html (2015-10-11)
    Open archived version from archive