CDuce: introduction, project status

This page is the support for the CDuce demo at the PLANX 2005 workshop (Longbeach). It has been designed to work with modern Gecko-based browser (with Javascript enabled).

Hightlights of CDuce

  • XML-oriented.
  • Type centric.
  • Set-theoretic types.
  • Based on XDuce regular expression types and patterns.
  • Also: general purpose features, including higher-order and overloaded functions.
  • Reasonnably efficient implementation.

Papers

  • White paper (PLANX 2002).
  • Language description (ICFP 2003).
  • Theoretical foundations (LICS 2002, JACM 2007).
  • Compilation of pattern matching (PLANX 2004, TCS 2004).
  • Query language (PADL 2005).
  • Foundation for polymorphic functions (ICFP 2011, and Zhiwu Xu's PhD thesis 2013).
(See: the CDuce team.)

Distribution

Public release since June 2003. Now at version 0.5.5, which includes a typeful and lightweight OCaml/CDuce interface.

Used in production (static/dynamic websites, code generation from GUI description, teaching, ...).

Development and research continue.

This demo

The demo illustrates the use of first-class functions in XML transformations. Here, functions are stored within documents.

Types, pattern matching

type Bib = [ Book* ]
type Book = <book ..>[ Title Subtitle? Author+ ]
type Title = <title>[ PCDATA ]
type Subtitle = <subtitle>[ PCDATA ]
type Author = <author>[ PCDATA ]

let title(Book -> String) 
  <book ..>[ <title>x _* ] -> x

let authors(Book -> [Author+]) 
  <book ..>[ (x::Author|_)* ] -> x

Sample values

let b1 : Book = <book>[ 
            <title>[ 'Object-Oriented Programming' ]
            <subtitle>[ 'A Unified Foundation' ]
            <author>[ 'Castagna' ] ]
let b2 : Book = <book>[
            <title>[ 'Persistent Object Systems' ]
            <author>[ 'Atkinson' ]
            <author>[ 'Benzaken' ]
            <author>[ 'Maier' ] ]
let bib : Bib = [ b1 b2 ]

Printing functions

type FBook = Book -> String
type ABook = <book print=FBook>[ Title Subtitle? Author+ ]
type ABib = [ ABook* ]
  (* Remark: ABook <= Book,  ABib <= Bib *)

let set(<book ..>c : Book)(f : FBook) : ABook = 
  <book print=f>c

let prepare(b : Bib) : ABib = 
  map b with x -> set x title

let abib = prepare bib

Display

type Ul = <ul>[ Li+ ]
type Li = <li>[ PCDATA ]

let display (ABib -> Ul; ABook -> Li)
 | <book print=f>_ & x -> <li>(f x)
 | [] -> raise "Empty bibliography"
 | p -> <ul>(map p with z -> display z)

let d = display abib

Changing the style

let change(p : Book -> Bool)
          (f : FBook)
          (b : ABib) : ABib =
 map b with x -> if (p x) then set x f else x

type HasSub = <_>[ _* Subtitle _* ]

let subtitle(Book & HasSub -> String) 
  <book ..>[ _* <subtitle>x _* ] -> x

let change_sub = 
change 
 (fun (Book -> Bool) HasSub -> `true | _ -> `false)
 (fun (b : Book) : String = 
   title b @ ": " @ subtitle (b :? HasSub))

let subtitle_first(Bib -> Bib; ABib -> ABib)
 [ (x::HasSub|y::_)* ] -> x @ y

Compilation of pattern-matching

debug compile 
(*typ*) [ Title Subtitle? Author+ ] 
(*pat*) [ (x::Author|_)* ]