<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hello,</div><div><br></div><div>Here is the latest Caml Weekly News, for the week of June 24 to July 1, 2008.</div><div><br></div><div>1) patterns v0.4</div><div>2) ocamlhackers.ning.com is open</div><div>3) OCaml PLEAC reaches 70%</div><div><br></div><div>========================================================================</div><div>1) patterns v0.4</div><div>Archive: <<a href="http://groups.google.com/group/fa.caml/browse_frm/thread/c292d01cec4d72b2#">http://groups.google.com/group/fa.caml/browse_frm/thread/c292d01cec4d72b2#</a>></div><div>------------------------------------------------------------------------</div><div>** Continuing the thread from last week, Nathaniel Gray said:</div><div><br></div><div>> Can someone summarise active patterns for us? The MSDN site</div><div>> containing the paper is down at the moment.</div><div><br></div><div>Sure. Active patterns are a lot like Wadler's "views", and thus are</div><div>similar to the stuff in micmatch. With active patterns you can invoke</div><div>functions (implicitly) within pattern matches and match the results,</div><div>which allows you to provide a "virtual" algebraic data structure for</div><div>any value you might want to match against. Here's an example from the</div><div>paper (using F# syntax):</div><div><br></div><div>open LazyList</div><div>let (|Cons|Nil|) l = if nonempty(l) then Cons(hd(l),tl(l)) else Nil</div><div><br></div><div>let rec pairSum xs =</div><div> match xs with</div><div> | Cons (x, Cons (y,ys)) -> consl (x+y) (lazy (pairSum ys))</div><div> | Cons (x, Nil ()) -> consl x (lazy nil)</div><div> | Nil () -> nil</div><div><br></div><div>This expands to:</div><div>let rec pairSum xs =</div><div> if nonempty xs then</div><div> let x, ys = hd xs, tl xs</div><div> if nonempty ys then</div><div> let y, zs = hd ys, tl ys</div><div> consl (x+y) (lazy (pairSum zs))</div><div> else consl x (lazy nil) )</div><div> else nil</div><div><br></div><div>There are other variations presented in the paper, including</div><div>parameterized patterns. These are nice for doing things like regular</div><div>expression matching. Again, from the paper:</div><div><br></div><div>let (|ParseRE|_|) re s =</div><div> let m = Regex(re).Match(s)</div><div> if m.Success</div><div> then Some [ for x in m.Groups -> x.Value ]</div><div> else None</div><div><br></div><div>let swap s =</div><div> match s with</div><div> | ParseRE "(\w+)-(\w+)" [l;r] -> r ^ "-" ^ l (* See below *)</div><div> | _ -> s</div><div><br></div><div>The matching syntax here is a bit confusing because it can be hard to</div><div>tell where parameters end and patterns begin. In the example above,</div><div>"(\w+)-(\w+)" is a parameter and [l;r] is a pattern. There's</div><div>definitely room for improvement over this syntax.</div><div><br></div><div>There are other variations and examples in the paper. I'd definitely</div><div>recommend reading it. If you still can't get it from the website I</div><div>can forward you a copy off-list.</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span></div><div>========================================================================</div><div>2) ocamlhackers.ning.com is open</div><div>Archive: <<a href="http://groups.google.com/group/fa.caml/browse_frm/thread/6c369078d4fdcea1#">http://groups.google.com/group/fa.caml/browse_frm/thread/6c369078d4fdcea1#</a>></div><div>------------------------------------------------------------------------</div><div>** Martin Jambon announced:</div><div><br></div><div>I couldn't resist creating an OCaml social network at Ning:</div><div><br></div><div> <<a href="http://ocamlhackers.ning.com/">http://ocamlhackers.ning.com/</a>></div><div><br></div><div>It's free and easy. Allows you to have your OCaml blog and exclusively OCaml</div><div>friends. If you like this, join now :-)</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span></div><div>========================================================================</div><div>3) OCaml PLEAC reaches 70%</div><div>Archive: <<a href="http://groups.google.com/group/fa.caml/browse_frm/thread/dc7f818a411020d4#">http://groups.google.com/group/fa.caml/browse_frm/thread/dc7f818a411020d4#</a>></div><div>------------------------------------------------------------------------</div><div>** Dave Benjamin announced:</div><div><br></div><div>The PLEAC project aims to translate the source code examples of the Perl</div><div>Cookbook to many programming languages. I have been working steadily for the</div><div>past two years toward completing the OCaml translation. As of today, it is</div><div>70.71% complete, in between Ruby (64.43%) and Python (85.43%).</div><div><br></div><div><<a href="http://pleac.sourceforge.net/">http://pleac.sourceforge.net/</a>></div><div><<a href="http://pleac.sourceforge.net/pleac_ocaml/index.html">http://pleac.sourceforge.net/pleac_ocaml/index.html</a>></div><div><br></div><div>Much of my recent work has been on the file I/O chapters, which cover the</div><div>topics of reading and writing to files using Pervasives and the Unix module.</div><div>The file access chapter covers argument parsing, file locking, buffering and</div><div>non-blocking I/O:</div><div><br></div><div><<a href="http://pleac.sourceforge.net/pleac_ocaml/fileaccess.html">http://pleac.sourceforge.net/pleac_ocaml/fileaccess.html</a>></div><div><br></div><div>The file contents chapter contains some helpful examples of working with</div><div>Streams and Buffers, line-indexing of large files, and manipulation of binary</div><div>data including an example of using Richard Jones' Bitmatch library to parse</div><div>and "tail" Linux's binary "utmp" database of login events:</div><div><br></div><div><<a href="http://pleac.sourceforge.net/pleac_ocaml/filecontents.html">http://pleac.sourceforge.net/pleac_ocaml/filecontents.html</a>></div><div><br></div><div>I have updated the PDF version as well, if you prefer to read PLEAC in an</div><div>offline format. You can download it here:</div><div><br></div><div><<a href="http://ramenlabs.com/pleac-pdf/pleac_ocaml.pdf">http://ramenlabs.com/pleac-pdf/pleac_ocaml.pdf</a>></div><div><br></div><div>As always, feedback, corrections, and contributions are more than welcome, and</div><div>I will do my best to make suggested improvements. I think that, despite being</div><div>somewhat Perl-centric and in need of more explanation, the OCaml PLEAC has</div><div>already become a valuable resource. I refer to it frequently myself. Hopefully</div><div>some day there will be a real OCaml Cookbook. In the meantime, there are a lot</div><div>of practical code snippets that can save a few trips to the manual / interface</div><div>files. I hope you find it useful as well.</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span></div><div>========================================================================</div><div>Using folding to read the cwn in vim 6+</div><div>------------------------------------------------------------------------</div><div>Here is a quick trick to help you read this CWN if you are viewing it using</div><div>vim (version 6 or greater).</div><div><br></div><div>:set foldmethod=expr</div><div>:set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'<1':1</div><div>zM</div><div>If you know of a better way, please let me know.</div><div><br></div><div>========================================================================</div><div>Old cwn</div><div>------------------------------------------------------------------------</div><div><br></div><div>If you happen to miss a CWN, you can send me a message</div><div>(<a href="mailto:alan.schmitt@polytechnique.org">alan.schmitt@polytechnique.org</a>) and I'll mail it to you, or go take a look at</div><div>the archive (<<a href="http://alan.petitepomme.net/cwn/">http://alan.petitepomme.net/cwn/</a>>) or the RSS feed of the</div><div>archives (<<a href="http://alan.petitepomme.net/cwn/cwn.rss">http://alan.petitepomme.net/cwn/cwn.rss</a>>). If you also wish</div><div>to receive it every week by mail, you may subscribe online at</div><div><<a href="http://lists.idyll.org/listinfo/caml-news-weekly/">http://lists.idyll.org/listinfo/caml-news-weekly/</a>> .</div><div><br></div><div>========================================================================</div><div class="AppleMailSignature" id="E12A09DE-ADCF-40D6-B7D4-306ED5CADD30"> <div><br class="khtml-block-placeholder"></div><div>-- </div><div>Alan Schmitt <<a href="http://alan.petitepomme.net/">http://alan.petitepomme.net/</a>></div><div><br class="khtml-block-placeholder"></div><div>The hacker: someone who figured things out and made something cool happen.</div><div> .O.</div><div> ..O</div><div> OOO</div><br class="Apple-interchange-newline"> </div><br></body></html>