[cwn] Attn: Development Editor, Latest Caml Weekly News
Alan Schmitt
alan.schmitt at polytechnique.org
Tue Jul 1 02:12:46 PDT 2008
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: <http://groups.google.com/group/fa.caml/browse_frm/thread/c292d01cec4d72b2#
>
------------------------------------------------------------------------
** 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: <http://groups.google.com/group/fa.caml/browse_frm/thread/6c369078d4fdcea1#
>
------------------------------------------------------------------------
** Martin Jambon announced:
I couldn't resist creating an OCaml social network at Ning:
<http://ocamlhackers.ning.com/>
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: <http://groups.google.com/group/fa.caml/browse_frm/thread/dc7f818a411020d4#
>
------------------------------------------------------------------------
** 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%).
<http://pleac.sourceforge.net/>
<http://pleac.sourceforge.net/pleac_ocaml/index.html>
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:
<http://pleac.sourceforge.net/pleac_ocaml/fileaccess.html>
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:
<http://pleac.sourceforge.net/pleac_ocaml/filecontents.html>
I have updated the PDF version as well, if you prefer to read PLEAC in
an
offline format. You can download it here:
<http://ramenlabs.com/pleac-pdf/pleac_ocaml.pdf>
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 (<http://alan.petitepomme.net/cwn/>) or the RSS feed of the
archives (<http://alan.petitepomme.net/cwn/cwn.rss>). If you also wish
to receive it every week by mail, you may subscribe online at
<http://lists.idyll.org/listinfo/caml-news-weekly/> .
========================================================================
--
Alan Schmitt <http://alan.petitepomme.net/>
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
More information about the caml-news-weekly
mailing list