From alan.schmitt at polytechnique.org Tue Jul 1 02:12:46 2008 From: alan.schmitt at polytechnique.org (Alan Schmitt) Date: Tue, 1 Jul 2008 11:12:46 +0200 Subject: [cwn] Attn: Development Editor, Latest Caml Weekly News Message-ID: <3F423D14-F165-41C7-9236-3FE67630761E@polytechnique.org> Hello, Here is the latest Caml Weekly News, for the week of June 24 to July 1, 2008. 1) patterns v0.4 2) ocamlhackers.ning.com is open 3) OCaml PLEAC reaches 70% ======================================================================== 1) patterns v0.4 Archive: ------------------------------------------------------------------------ ** Continuing the thread from last week, Nathaniel Gray said: > Can someone summarise active patterns for us? The MSDN site > containing the paper is down at the moment. Sure. Active patterns are a lot like Wadler's "views", and thus are similar to the stuff in micmatch. With active patterns you can invoke functions (implicitly) within pattern matches and match the results, which allows you to provide a "virtual" algebraic data structure for any value you might want to match against. Here's an example from the paper (using F# syntax): open LazyList let (|Cons|Nil|) l = if nonempty(l) then Cons(hd(l),tl(l)) else Nil let rec pairSum xs = match xs with | Cons (x, Cons (y,ys)) -> consl (x+y) (lazy (pairSum ys)) | Cons (x, Nil ()) -> consl x (lazy nil) | Nil () -> nil This expands to: let rec pairSum xs = if nonempty xs then let x, ys = hd xs, tl xs if nonempty ys then let y, zs = hd ys, tl ys consl (x+y) (lazy (pairSum zs)) else consl x (lazy nil) ) else nil There are other variations presented in the paper, including parameterized patterns. These are nice for doing things like regular expression matching. Again, from the paper: let (|ParseRE|_|) re s = let m = Regex(re).Match(s) if m.Success then Some [ for x in m.Groups -> x.Value ] else None let swap s = match s with | ParseRE "(\w+)-(\w+)" [l;r] -> r ^ "-" ^ l (* See below *) | _ -> s The matching syntax here is a bit confusing because it can be hard to tell where parameters end and patterns begin. In the example above, "(\w+)-(\w+)" is a parameter and [l;r] is a pattern. There's definitely room for improvement over this syntax. There are other variations and examples in the paper. I'd definitely recommend reading it. If you still can't get it from the website I can forward you a copy off-list. ======================================================================== 2) ocamlhackers.ning.com is open Archive: ------------------------------------------------------------------------ ** Martin Jambon announced: I couldn't resist creating an OCaml social network at Ning: It's free and easy. Allows you to have your OCaml blog and exclusively OCaml friends. If you like this, join now :-) ======================================================================== 3) OCaml PLEAC reaches 70% Archive: ------------------------------------------------------------------------ ** Dave Benjamin announced: The PLEAC project aims to translate the source code examples of the Perl Cookbook to many programming languages. I have been working steadily for the past two years toward completing the OCaml translation. As of today, it is 70.71% complete, in between Ruby (64.43%) and Python (85.43%). Much of my recent work has been on the file I/O chapters, which cover the topics of reading and writing to files using Pervasives and the Unix module. The file access chapter covers argument parsing, file locking, buffering and non-blocking I/O: The file contents chapter contains some helpful examples of working with Streams and Buffers, line-indexing of large files, and manipulation of binary data including an example of using Richard Jones' Bitmatch library to parse and "tail" Linux's binary "utmp" database of login events: I have updated the PDF version as well, if you prefer to read PLEAC in an offline format. You can download it here: As always, feedback, corrections, and contributions are more than welcome, and I will do my best to make suggested improvements. I think that, despite being somewhat Perl-centric and in need of more explanation, the OCaml PLEAC has already become a valuable resource. I refer to it frequently myself. Hopefully some day there will be a real OCaml Cookbook. In the meantime, there are a lot of practical code snippets that can save a few trips to the manual / interface files. I hope you find it useful as well. ======================================================================== Using folding to read the cwn in vim 6+ ------------------------------------------------------------------------ Here is a quick trick to help you read this CWN if you are viewing it using vim (version 6 or greater). :set foldmethod=expr :set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'<1':1 zM If you know of a better way, please let me know. ======================================================================== Old cwn ------------------------------------------------------------------------ If you happen to miss a CWN, you can send me a message (alan.schmitt at polytechnique.org) 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 at . ======================================================================== -- Alan Schmitt The hacker: someone who figured things out and made something cool happen. .O. ..O OOO -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20080701/1ab7ada2/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part Url : http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20080701/1ab7ada2/attachment.pgp From alan.schmitt at polytechnique.org Tue Jul 8 02:12:09 2008 From: alan.schmitt at polytechnique.org (Alan Schmitt) Date: Tue, 8 Jul 2008 11:12:09 +0200 Subject: [cwn] Attn: Development Editor, Latest Caml Weekly News Message-ID: <8C03B944-37EB-429B-949B-0E48BAF0799D@polytechnique.org> Hello, Here is the latest Caml Weekly News, for the week of July 1 to 8, 2008. 1) ooauth 0.1 2) ethreads relesase 3) Logic File System 4) Newbie question: OCaml equivalent of Haskell's show? 5) Bisect 1.0 alpha ======================================================================== 1) ooauth 0.1 Archive: ------------------------------------------------------------------------ ** Jake Donham announced: Skydeck is pleased to announce ooauth, an implementation of the OAuth 1.0 protocol for OCaml, as well as an OCaml binding to our web API (providing access to your cell phone call log). More at The OAuth library provides both the "service provider" and "consumer" sides of OAuth, so you can use it to build a web API of your own, or to access one of the increasing number of APIs supporting OAuth (such as the Google data APIs). More at If you'd like to try Skydeck (and have a cell phone with a major American carrier), drop me an email (of course you don't need a Skydeck account to use the OAuth library). ======================================================================== 2) ethreads relesase Archive: ------------------------------------------------------------------------ ** Satoshi Ogasawara announced: I'm pleased to announce a new release of 'ethreads', small codes for multi-thread programming. This library has - extended Threads.Event module. - threadless ivar and mvar, inter-thread shared variable. - mailbox(queue), broadcast channel, timeout, meta-RPC. I believe these features are necessary for channel passing style multi- thread programming with OCaml. More at: Project Home Page: Signatures : ======================================================================== 3) Logic File System Archive: ------------------------------------------------------------------------ ** Yoann Padioleau announced: I am pleased to announce the release of the Logic File System (LFS). LFS is a very expressive file system coded in OCaml. LFS enables the user to access his files through an additionnal mountpoint, /lfs, where powerful logic queries can be issued and navigation can be done through different dimensions, like date, size, or extension. For instance, LFS allows the user to perform the following commands in the shell: $ cd /lfs/ext:mp3|ext:ogg/year:1973/genre:Disco/ $ ls artist:BeeGees/ artist:DonnaSummer/ artist:Chic/ ... $ cd /lfs/ext:ml|ext:mli/.ext $ ls list.ml list.mli array.ml array.mli ... It uses FUSE (and ocamlfuse). LFS just acts like an additionnal way to access your files. No need to migrate your data to LFS. Homepage: Tar/GZ: Quick install guide: Tutorial: ======================================================================== 4) Newbie question: OCaml equivalent of Haskell's show? Archive: ------------------------------------------------------------------------ ** Antony Courtney asked and Richard Jones answered: > I'm an experienced Haskell hacker trying OCaml for the first time. > > One thing I am desperately searching for but have been unable to find > is some direct runtime access to the string representation of > arbitrary OCaml values. I have written a little option pricer that > constructs a > float option array array > in a function. I've got a little buglet in my function so I'd like to > print the intermediate states of this value from inside the function. > How do I do that, short of writing my own recursive pretty printer / > formatter? An OCaml form of the Haskell Show type class would be > great, but a hack to provide programmatic access to the polymorphic > pretty printer that obviously already exists in the OCaml toplevel > would be fine. > > I've scoured the standard library docs, manual, tutorials and a few > books, looked at the FAQ and am amazed that I haven't found the answer > to this. I am hopefully just missing something obvious; would be > grateful if someone could point me towards the answer! Note that OCaml doesn't carry very much information at runtime about what is represented in a value. However there are various generic printers around. Probably your best bet for a quick and dirty hack is to use the 'Std.dump' function in extlib (). This can turn anything into a string, and tries to produce something which looks similar to an OCaml toplevel value. Documentation for Std.dump: If you want to go further than this and have OCaml write a pretty- printer for your types, then you'll want to look at one of the following projects (and probably others ...) Another alternative is to run your code in the OCaml toplevel. ** Jon Harrop also answered: > One thing I am desperately searching for but have been unable to find > is some direct runtime access to the string representation of > arbitrary OCaml values. OCaml has no run-time type information, no structural pretty printers in compiled code and no type classes to help you implement your own in source code. > I have written a little option pricer that constructs a > float option array array > in a function. I've got a little buglet in my function so I'd like to > print the intermediate states of this value from inside the function. > How do I do that, short of writing my own recursive pretty printer / > formatter? You basically have two choices: .. Run in the top-level and get the value you require as the result of evaluating an expression (e.g. by raising an exception, or by setting a mutable). .. Write your own print function(s) and call them. The benefit of the latter is, of course, that it works from compiled code. > An OCaml form of the Haskell Show type class would be great, IMHO, type classes are great for some things but pretty printing is not one of them. Start with a function to print a list with an arbitrary separator: # open Format;; # let rec fprintfs sep f ff = function | [] -> () | [h] -> fprintf ff "%a" f h | h::t -> fprintf ff "%a%a%a" f h sep () (fprintfs sep f) t;; val fprintfs : (Format.formatter -> unit -> unit) -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a list -> unit = For example, we can now write a function to pretty print a list in Mathematica notation: # let fprintf_mma ff list = let sep ff () = fprintf ff ",@ " in let int ff = fprintf ff "%d" in fprintf ff "{@[%a@]}" (fprintfs sep int) list;; val fprintf_mma : Format.formatter -> int list -> unit = # fprintf std_formatter "%a\n" fprintf_mma (Array.to_list(Array.init 100 (fun n -> n)));; {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99} - : unit = () Note the automatically-aligned wrapping thanks to OCaml's pretty printing "Format" module and the use of "@[", "@ " and "@]" in my code. This also works from compiled code and is an excellent way to print indented source code (e.g. when generating other languages). To pretty print a generic array: # let fprintf_array f ff array = let sep ff () = fprintf ff ";@ " in fprintf ff "[|@[%a@]|]" (fprintfs sep f) (Array.to_list array);; val fprintf_array : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a array -> unit = To print an option: # let rec fprintf_opt f ff = function | None -> fprintf ff "None" | Some x -> fprintf ff "Some %a" f x;; val fprintf_opt : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a option -> unit = Now you can print your array of arrays of float options: # let print ff xss = let float ff = fprintf ff "%g" in fprintf_array (fprintf_array (fprintf_opt float)) ff xss;; val print : Format.formatter -> float option array array -> unit = # fprintf std_formatter "%a\n" print [|[|Some 3.; None; None|]; [|None; Some 5.; None|]; [|Some 1.|]|];; [|[|Some 3; None; None|]; [|None; Some 5; None|]; [|Some 1|]|] - : unit = () > but a hack to provide programmatic access to the polymorphic > pretty printer that obviously already exists in the OCaml toplevel > would be fine. In addition to Richard's suggestions, you might look at generating OCaml expressions using camlp4 and then printing those instead. Just an idea (I've never tried it). > I've scoured the standard library docs, manual, tutorials and a few > books, looked at the FAQ and am amazed that I haven't found the answer > to this. I am hopefully just missing something obvious; would be > grateful if someone could point me towards the answer! Surprisingly, structural printing is something that OCamlers rarely do. As part of my evolution as a programmer I had migrated everything from C+ + and Mathematica to OCaml a few years ago but I am actually about to move a little parsing-related project from OCaml to F# simply because its built-in pretty printers make life so much easier. Anyway, I shall write an OCaml Journal article about OCaml's wonderful "Format" module. Incidentally, the OCaml Journal has recovered from a lull in Q1 and has really started to pick up now. So I still think there is plenty of opportunity for budding authors to write OCaml books! ======================================================================== 5) Bisect 1.0 alpha Archive: ------------------------------------------------------------------------ ** Xavier Clerc announced: This post announces the 1.0 alpha version of Bisect. Bisect is a coverage tool for the Objective Caml language. Home page: Features: - lightweight tool - camlp4-based instrumentation of source files - HTML-based report with replica of original source code annotated with coverage information - per-file and application-wide statistics Dependencies: - Objective Caml 3.10.2 - Unix module Planned features: - other report formats (framed HTML, XML, bare text) - thread support - some nice features borrowed from HPC () This is my very first non-trivial camlp4-based application, and would be glad to hear comment and suggestions about Bisect, and the way it could be enhanced. ======================================================================== Using folding to read the cwn in vim 6+ ------------------------------------------------------------------------ Here is a quick trick to help you read this CWN if you are viewing it using vim (version 6 or greater). :set foldmethod=expr :set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'<1':1 zM If you know of a better way, please let me know. ======================================================================== Old cwn ------------------------------------------------------------------------ If you happen to miss a CWN, you can send me a message (alan.schmitt at polytechnique.org) 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 at . ======================================================================== -- Alan Schmitt The hacker: someone who figured things out and made something cool happen. .O. ..O OOO -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20080708/d22dd0a3/attachment-0001.html -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part Url : http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20080708/d22dd0a3/attachment-0001.pgp From alan.schmitt at polytechnique.org Tue Jul 15 00:56:43 2008 From: alan.schmitt at polytechnique.org (Alan Schmitt) Date: Tue, 15 Jul 2008 09:56:43 +0200 Subject: [cwn] Attn: Development Editor, Latest Caml Weekly News Message-ID: <0AA1A165-D821-41CC-B6E5-1323039F771F@polytechnique.org> Hello, Here is the latest Caml Weekly News, for the week of July 8 to 15, 2008. 1) New library: Easy-format 0.9.0 2) Troublesome nodes 3) Name of currently executing function ======================================================================== 1) New library: Easy-format 0.9.0 Archive: ------------------------------------------------------------------------ ** Martin Jambon announced: I would like to announce a small library (a module in fact) that is meant to make it easy to produce pretty-printed text: The data to be printed goes through a tree that carries all the information required for pretty-printing. After that, a single call to Easy_format.Pretty.to_stdout (for instance) outputs the indented result. There's a reasonably complete example at ** He later added: I've just released a richer version of Easy-format. The main URL is still It now offers the following additional features: - Support for separators that stick to the next list item (e.g. "|") - More wrapping options - Added Custom kind of nodes for using Format directly or existing pretty-printers - Support for markup and escaping, allowing to produce colorized output (HTML, terminal, ...) without interfering with the computation of line breaks and spacing. Easy-format now takes advantage of most features of the Format module, with the notable exception of tabulation boxes. I'd be curious so see any interesting use of tabulation boxes. This release has slight incompatibilities with version 0.9.0 which was released earlier this week, simply because more options were added: - Deprecated use of Easy_format.Param. Instead, inherit from Easy_format.list, Easy_format.label or Easy_format.atom. - Atom nodes have now one additional argument for parameters. - All record types have been extended with more fields. Using the "with" mechanism for inheritance is the best way of limiting future incompatibilities. ======================================================================== 2) Troublesome nodes Archive: ------------------------------------------------------------------------ ** Deep in this thread, Dario Teixeira said: For the sake of future reference, I'm going to summarise the solution to the original problem, arrived at thanks to the contribution of various people in this list (your help was very much appreciated!). This might came in handy in the future if you run into a similar problem. So, we have a document composed of a sequence of nodes. There are four different kinds of nodes, two of which are terminals (Text and See) and two of which are defined recursively (Bold and Mref). Both See and Mref produce links, and we want to impose a constraint that no link node shall be the immediate ancestor of another link node. An additional constraint is that nodes must be created via constructor functions. Finally, the structure should be pattern-matchable, and the distinction between link/nonlink nodes should be preserved so that Node-to-Node functions do not require code duplication and/or ugly hacks. Using conventional variants, the structure can be represented as follows. Alas, this solution is not compatible with constructor functions and requires unwanted scaffolding: module Ast = struct type super_node_t = | Nonlink_node of nonlink_node_t | Link_node of link_node_t and nonlink_node_t = | Text of string | Bold of super_node_t list and link_node_t = | Mref of string * nonlink_node_t list | See of string end Below is the solution that was finally obtained. Nodes are represented using polymorphic variants, and the module itself is recursive to get around the "type not fully defined" problem: module rec Node: sig type nonlink_node_t = [ `Text of string | `Bold of Node.super_node_t list ] type link_node_t = [ `See of string | `Mref of string * nonlink_node_t list ] type super_node_t = [ nonlink_node_t | link_node_t ] val text: string -> nonlink_node_t val bold: [< super_node_t] list -> nonlink_node_t val see: string -> link_node_t val mref: string -> nonlink_node_t list -> link_node_t end = struct type nonlink_node_t = [ `Text of string | `Bold of Node.super_node_t list ] type link_node_t = [ `See of string | `Mref of string * nonlink_node_t list ] type super_node_t = [ nonlink_node_t | link_node_t ] let text txt = `Text txt let bold seq = `Bold (seq :> super_node_t list) let see ref = `See ref let mref ref seq = `Mref (ref, seq) end If you try it out, you will see that this solution enforces the basic node constraints. The values foo1-foo4 are valid, whereas the compiler won't accept foo5, because a link node is the parent of another: open Node let foo1 = text "foo" let foo2 = bold [text "foo"] let foo3 = mref "ref" [foo1; foo2] let foo4 = mref "ref" [bold [see "ref"]] let foo5 = mref "ref" [see "ref"] Now, suppose you need to create an Ast-to-Node sets of functions (a likely scenario if you are building a parser for documents). The solution is fairly straightforward, but note the need to use the cast operator :> to promote link/nonlink nodes to supernodes: module Ast_to_Node = struct let rec convert_nonlink_node = function | Ast.Text txt -> Node.text txt | Ast.Bold seq -> Node.bold (List.map convert_super_node seq) and convert_link_node = function | Ast.Mref (ref, seq) -> Node.mref ref (List.map convert_nonlink_node seq) | Ast.See ref -> Node.see ref and convert_super_node = function | Ast.Nonlink_node node -> (convert_nonlink_node node :> Node.super_node_t) | Ast.Link_node node -> (convert_link_node node :> Node.super_node_t) end Finally, another common situation is to build functions to process nodes. The example below is that of a node-to-node "identity" module. Again, it is fairly straightforward, but note the use of the operator # and the need to cast link/nonlink nodes to supernodes: module Node_to_Node = struct open Node let rec convert_nonlink_node = function | `Text txt -> text txt | `Bold seq -> bold (List.map convert_super_node seq) and convert_link_node = function | `See ref -> see ref | `Mref (ref, seq) -> mref ref (List.map convert_nonlink_node seq) and convert_super_node = function | #nonlink_node_t as node -> (convert_nonlink_node node :> super_node_t) | #link_node_t as node -> (convert_link_node node :> super_node_t) end ** He later added: Sorry, but in the meantime I came across two problems with the supposedly ultimate solution I just posted. I have a correction for one, but not for the other. The following statements trigger the first problem: let foo1 = text "foo" let foo2 = see "ref" let foo3 = bold [foo1; foo2] Error: This expression has type Node.link_node_t but is here used with type Node.nonlink_node_t These two variant types have no intersection The solution that immediately comes to mind is to make the return types for the constructor functions open: (I can see no disadvantage with this solution; please tell me if you find any) module rec Node: sig type nonlink_node_t = [ `Text of string | `Bold of Node.super_node_t list ] type link_node_t = [ `See of string | `Mref of string * nonlink_node_t list ] type super_node_t = [ nonlink_node_t | link_node_t ] val text: string -> [> nonlink_node_t] val bold: [< super_node_t] list -> [> nonlink_node_t] val see: string -> [> link_node_t] val mref: string -> nonlink_node_t list -> [> link_node_t] end = struct type nonlink_node_t = [ `Text of string | `Bold of Node.super_node_t list ] type link_node_t = [ `See of string | `Mref of string * nonlink_node_t list ] type super_node_t = [ nonlink_node_t | link_node_t ] let text txt = `Text txt let bold seq = `Bold (seq :> super_node_t list) let see ref = `See ref let mref ref seq = `Mref (ref, seq) end The second problem, while not a show-stopper, may open a hole for misuse of the module, so I would rather get it fixed. Basically, while the module provides constructor functions to build nodes, nothing prevents the user from bypassing them and constructing nodes manually. The obvious solution of declaring the types "private" results in an "This fixed type has no row variable" error. Any way around it? ======================================================================== 3) Name of currently executing function Archive: ------------------------------------------------------------------------ ** Dave Benjamin asked and blue storm answered: > Is there any way to find out the name of the currently executing > function from within an OCaml program? I guess, technically, I'm > interested in the grandparent. Something that would allow this: > > let log msg = > Printf.eprintf "%s: %s\n%!" > (get_caller_function_name ()) > msg > > I'm guessing the above is not possible, but perhaps there's some way to > accomplish this using some combination of camlp4, back traces, > profiling, or debugging? Here is a little camlp4 code for an ad-hoc solution : It's based upon the Camlp4Filters/Camlp4Profiler.ml from the camlp4 distribution. The GenericMake functor will traverse your code and apply the parametrized function to the body of each function declaration. You can use it with a functor providing a (with_fun_name : string -> Ast.expr -> Ast.expr), transforming the Ast to your liking, given the function name. I've written a small LoggingDecorator module that operates on the __LOG__ identifier. Example code : let __LOG_FUNC__ func msg = Printf.eprintf "in function %s: %s\n%!" func msg let test_function p = if not p then __LOG__ "p is false !" It will replace the __LOG__ identifier with a __LOG_FUNC__ "p". You can change that behavior, in particular you could be interested (for logging purpose) in the location of the function declaration, not only his name : see how the initial Camlp4Profiler behavior (wich i kept in the ProfilingDecorator) do that (Loc.dump). ======================================================================== Using folding to read the cwn in vim 6+ ------------------------------------------------------------------------ Here is a quick trick to help you read this CWN if you are viewing it using vim (version 6 or greater). :set foldmethod=expr :set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'<1':1 zM If you know of a better way, please let me know. ======================================================================== Old cwn ------------------------------------------------------------------------ If you happen to miss a CWN, you can send me a message (alan.schmitt at polytechnique.org) 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 at . ======================================================================== -- Alan Schmitt The hacker: someone who figured things out and made something cool happen. .O. ..O OOO -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20080715/ca7ace87/attachment.htm -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part Url : http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20080715/ca7ace87/attachment-0001.pgp From alan.schmitt at polytechnique.org Tue Jul 22 03:06:16 2008 From: alan.schmitt at polytechnique.org (Alan Schmitt) Date: Tue, 22 Jul 2008 12:06:16 +0200 Subject: [cwn] Attn: Development Editor, Latest Caml Weekly News Message-ID: <4D75CCF0-7B0E-499B-9C0A-040383F85882@polytechnique.org> Hello, Here is the latest Caml Weekly News, for the week of July 15 to 22, 2008. As I will be moving from Italy to France next week, there will not be a CWN. I will try the week after that if I have internet access. Good vacations to all! 1) Profiling ocaml using gprof 2) ocaml-bitstring 1.9.6 (formerly known as ocaml-bitmatch) 3) Position 4) "OCaml Developers" group just created on LinkedIn 5) NW Functional Programming Interest Group 6) Name of currently executing function 7) Commercial Users of Functional Programming Workshop Call for Participation 8) Understanding monads ======================================================================== 1) Profiling ocaml using gprof Archive: ------------------------------------------------------------------------ ** Arthur Chan asked and Richard Jones answered: > Is gprof better for profiling ocaml than ocaml's own profilers? They are slightly different. I use 'gprof' all the time because I tend to only use natively compiled executables. 'gprof' is the ordinary GNU profiling tool that tells you which function is being run most often and some limited information about the call path into that function. It's pretty useful for simple profiling where you're looking for obvious problems. 'ocamlprof' is a bit different. Last time I used it [which was a few years ago, so maybe it's different now], it only worked on bytecode. It outputs your original code with annotations telling you how often each expression was run. So this isn't time taken (each expression can take a different amount of time to execute, and this time isn't shown), but how often a particular path through the code is taken. > How would you go about figuring out that that particular function stub is > string concat? > > 'camlPervasives__$5e_136'. In 'gprof' there's a simple name mangling used to map OCaml function names to assembler symbols. Once you understand it, you'll find it easy to follow. First of all note that OCaml function names aren't unique, eg in the following code: let f () = printf "this is the first f()\n" let f () = printf "this is the second f()\n"; f () ;; f () The assembler symbol is: "caml" ^ Modulename ^ "__" ^ functionname ^ "_" ^ uniquenumber 'uniquenumber' is just a counter added to function names by the compiler to make sure that functions which have the same name will have different symbols. So when I compiled the code above in a file called 'test.ml' (hence a module called Test), in my case I ended up with two symbols called: camlTest__f_77 camlTest__f_78 where '77' and '78' are arbitrary. You can check this by looking at the assembler output from the compiler (ocamlopt -S). If a function name contains an operator symbol (eg. (^) ) then a $xx hex code is used. I guess in theory one could write an OCaml symbol filter, similar to c++filt [] ======================================================================== 2) ocaml-bitstring 1.9.6 (formerly known as ocaml-bitmatch) Archive: ------------------------------------------------------------------------ ** Richard Jones announced: I'm please to announce version 1.9.6 of ocaml-bitstring (formerly known as ocaml-bitmatch). The home page has changed again, so please update any bookmarks or links to point to the new home page here: Version 1.9.6 features 'check()', 'bind()' and 'save_offset_to()' qualifiers which give you much greater control over the matching process. For example: bitmatch packet with | { len : 16 : check (len > 0), bind (len*8); data : len : string; crc : 32 : check (crc_ok data crc), save_offset_to (crc_offset) } -> printf "length of data (in bits) = %d\n" len; printf "offset of CRC in packet (in bits) = %d\n" crc_offset | { _ } -> printf "bad packet\n" We have also fixed some bugs, clarified the licensing everywhere (for Debian), and improved the META file. A troublesome company sent my employer a Cease and Desist notice, claiming that their trademark on the word "BitMatch" for "Computer software for comparing and analyzing computer software"[sic] covered ocaml-bitmatch. No such thing is true, but because of the time and expense of dealing with the legal process we have decided to rename ocaml-bitmatch to ocaml-bitstring for their benefit (still very time-consuming). As a result, we are gradually moving the old website, wiki etc. to the new home page above, and some internals will change (code will be backwards-compatible, but you may need to make some changes to build scripts). Thanks to Sylvain Le Gall for offering hosting. ======================================================================== 3) Position Archive: ------------------------------------------------------------------------ ** Ihsan Ecemis announced: We are a fast-paced, VC-funded, Boston-based startup currently building our flagship product targeted at the scientific community. We need a few sharp minds to help us. We are using OCaml in our core simulation technology. We are looking for someone who is mathematically minded, has fun with his work, takes pride in its quality, and learns quickly. If facing the challenges of building cutting-edge technologies is your idea of a good time, then you are going to love working with us. We are solving hard problems and having a lot of fun doing it. Join us. Qualifications * 3+ years of experience in functional programming, preferably in OCaml * Strong CS fundamentals The best candidates will have experience with: * Dealing with a large code base, complex data structures, and intricate control loops * Scalability and performance issues * Simulations of complex systems * Conducting research on basic algorithms, mathematics, agent-based models Instructions To apply for this position, submit your resume to jobs at plectix.com. ======================================================================== 4) "OCaml Developers" group just created on LinkedIn Archive: ------------------------------------------------------------------------ ** Stefano Zacchiroli announced: In case you are in the LinkedIn professional network, you might be interested in knowing that I've just created an OCaml group there: . It is called OCaml Developers and it is intended to provide yet another way for the community of OCaml programmers to advertise themselves to the professional world. I was surprised by the fact there were no professional group related to OCaml there, and that's why I created one. The only group I found mentioning OCaml was a very narrow one about the usage of functional programming for financial purposes, probably all Jane St employees are members Feel free to join the new group. Also, if you want to spare the duty of checking/accepting new people into the group drop me a line, you will be more than welcome! ======================================================================== 5) NW Functional Programming Interest Group Archive: ------------------------------------------------------------------------ ** Greg Meredith announced: This is just a friendly reminder to Northwest functionally minded folks that this month's meeting is to be held The Seattle Public Library 5009 Roosevelt Way N.E. Seattle, WA 98105 206-684-4063 from 18.30 - 19:45 on July 23rd. We'll be getting a demo of a scala-lift-based application that compiles a graphical rendition of functional expressions into expressions in a functional language. Hope to see you there. ======================================================================== 6) Name of currently executing function Archive: ------------------------------------------------------------------------ ** Continuing the thread from last week, Dave Benjamin announced: Thanks again for your help, blue storm. I condensed this technique into a simple example for PLEAC, which I just committed here: It allows you to write this: (* An example named function. *) let test_function () = let str = "Hello, world!" in let num = 42 in LOG "str=\"%s\", num=%d" str num; print_endline "test complete" (* Some code to run at the toplevel. *) let () = LOG "not in a function"; test_function () And get the following output: [main.ml]: not in a function test_function[main.ml]: str="Hello, world!", num=42 test complete ======================================================================== 7) Commercial Users of Functional Programming Workshop Call for Participation Archive: ------------------------------------------------------------------------ ** Jim Grundy announced: Commercial Users of Functional Programming Workshop (CUFP) 2008 Functional Programming As a Means, Not an End Call for Participation Sponsored by SIGPLAN Co-located with ICFP 2008 __________________________________________________________________ 26 September 2008 Victoria, Canada Registration opens in late July through __________________________________________________________________ Functional languages have been under academic development for over 25 years, and remain fertile ground for programming language research. Recently, however, developers in industrial, governmental, and open source projects have begun to use functional programming successfully in practical applications. In these settings, functional programming has often provided dramatic leverage, including whole new ways of thinking about the original problem. The goal of the CUFP workshop is to act as a voice for these users of functional programming. The workshop supports the increasing viability of functional programming in the commercial, governmental, and open-source space by providing a forum for professionals to share their experiences and ideas, whether those ideas are related to business, management, or engineering. The workshop is also designed to enable the formation and reinforcement of relationships that further the commercial use of functional programming. Providing user feedback to language designers and implementors is not a primary goal of the workshop, though it will be welcome if it occurs. Program CUFP 2008 will last a full day and feature a discussion session and the following presentations: Don Syme (Microsoft) Invited Presentation: Why Microsoft is Investing in Functional Programming David Balaban (Amgen) Minimizing the Immune Response to Functional Programming at Amgen Francesco Cesarini (Erlang Training and Consulting) The Mobile Messaging Gateway, from Idea to Prototype to Launch in 12 months Jake Donham (Skydeck) From OCaml to Javascript at Skydeck Nick Gerakines (Yahoo) Developing Erlang at Yahoo Tom Hawkins (Eaton Corporation) Controlling Hybrid Vehicles with Haskell Bob Ippolito (Mochimedia) Ad Serving with Erlang Anil Madhavapeddy (Citrix) Xen and the art of OCaml Howard Mansell (Credit Suisse) Quantitative Finance in F# Jeff Polakow (Deutsche Bank) Is Haskell ready for everyday computing? David Pollak (Lift web framework) Buy a Feature: an adventure in immutability and Actors Gregory Wright (Antiope) Functions to Junctions: Ultra Low Power Chip Design With Some Help From Haskell There will be no published proceedings, as the meeting is intended to be more a discussion forum than a technical interchange. See for more information, including presentation abstracts and the most recent schedule information. Program Committee * Lennart Augustsson * Matthias Blume * Adam Granicz * Jim Grundy(co-chair) * Andy Martin * Yaron Minsky * Simon Peyton Jones(co-chair) * Ulf Wiger This will be the fifth CUFP; see CUFP 2004 CUFP 2005, CUFP 2006, and CUFP 2007 for information about the earlier meetings, including reports from attendees and video of the most recent talks. ======================================================================== 8) Understanding monads Archive: ------------------------------------------------------------------------ ** Paolo Donadeo asked and Till Crueger answered: > I like functional programming, but monads [1] must be too little to be > grabbed by my mind. This time the interest in monads was aroused by > the interesting article of David Teller, Arnaud Spiwack and Till > Varoquaux [2] about the error monad, but for using the library they > wrote I need at least some knowledge about monads and the do- notation. it might take a while, but it's worth the effort... It took me some time to get the concept as well. Don't worry it doesn't have to do with your IQ. > I ask you all: can anyone make me a practical example, something > involving strings, files, the network, an image or sound processing > algorithm, something vaguely real? Not abstract mathematical > structures, beautiful algebraic properties and general statements, > please: the net is full of such tutorials, especially Haskell fan > sites ;-) hmm, very informaly speaking, monads allow you to "wrap up" some other value, or a set of those... Then of course there are lot's of way's to wrap something up, so this is really abstract. One good thing that helped me a lot, was to implement the monads myself in OCaml, even though i hadn't understood them fully at that time. Try for example to build your own I/O Monad and it will start to get more clearly how it works. > [1] I suggest this one instead as a good starting point: > [2] ** Fabrice Marchant then said: > I suggest this one instead as a good starting point: > Among the links appearing at the bottom of this document, this non theoretical-one appears the coolest to understand for me. The "pure function debugging" example allows simple OCaml experimentions : ** Gabriel Kerneis answered the original question: Xavier Leroy's lesson on monads [1] will certainly be too abstract for you, but the accompanying Caml code [2] might help you to grasp the concept. You will find there a lot of example of useful monads. You should have read some tutorial before, though, not to get lost. Another very concrete example is Lwt [3], a cooperative thread library written in monadic style. Don't hesitate to follow the link, it's a documentation targeted at programmers, without categorical issues and so on. You will need to read a more general tutorial on monads then, to get the general idea, but it could be a good starting point to "bind" and "return" operators. [1] [2] [3] ======================================================================== Using folding to read the cwn in vim 6+ ------------------------------------------------------------------------ Here is a quick trick to help you read this CWN if you are viewing it using vim (version 6 or greater). :set foldmethod=expr :set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'<1':1 zM If you know of a better way, please let me know. ======================================================================== Old cwn ------------------------------------------------------------------------ If you happen to miss a CWN, you can send me a message (alan.schmitt at polytechnique.org) 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 at . ======================================================================== -- Alan Schmitt The hacker: someone who figured things out and made something cool happen. .O. ..O OOO -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20080722/1c44b523/attachment-0001.html -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part Url : http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20080722/1c44b523/attachment-0001.pgp