Commit edab9038 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2002-10-26 21:36:03 by cvscast] Empty log message

Original author: cvscast
Date: 2002-10-26 21:37:51+00:00
parent 9fdf4177
type Biblio = <bibliography>[Heading Paper*];;
type Heading = <heading>[String];;
type Paper = <paper>[Author+ Title Conference File];;
type Author = <author>[String];;
type Title = <title>[String];;
type Conference = <conference>[String];;
type File = <file>[String];;
type Html = <html>[Head? Body];;
type Head = <head>[ <title>[String] ];;
type Body = <body>[Mix*];;
type Mix = <h1>[Mix*]
| <a href=[String]>[Mix*]
| <p>[Mix*]
| <em>[Mix*]
| <ul>[ <li>[Mix*] +]
| Char;;
let fun do_authors ([Author+] -> [Mix*])
| [ <author>a ] -> a
| [ <author>a <author>b ] -> a @ " and, " @ b
| [ <author>a; x] -> a @ ", " @ do_authors x
in
let fun do_paper (Paper -> <li>[Mix*])
<paper>[ x::(_*) <title>t <conference>c <file>f ] ->
(* Here, type inference says: x : [Author+] ... *)
let authors = do_authors x in
<li>([ <a href=f>t ] @ authors @ "; in " @ [ <em>c ] @ "." )
in
let fun do_biblio (Biblio -> Html)
<bibliography>[ <heading>h; p ] ->
let body = match p with
| [] -> "Empty bibliography"
| l -> [ <h1>h <ul>(map l with x -> do_paper x) ]
in
<html>[ <head>[ <title>h ] <body>body ]
in
let bib : Biblio =
<bibliography>[
<heading>"Alain Frisch's bibliography"
<paper>[
<author>"Alain Frisch"
<author>"Giuseppe Castagna"
<author>"Vronique Benzaken"
<title>"Semantic subtyping"
<conference>"LICS 02"
<file>"semsub.ps.gz"
]
<paper>[
<author>"Mariangiola Dezani-Ciancaglini"
<author>"Alain Frisch"
<author>"Elio Giovannetti"
<author>"Yoko Motohama"
<title>"The Relevance of Semantic Subtyping"
<conference>"ITRS'02"
<file>"itrs02.ps.gz"
]
<paper>[
<author>"Vronique Benzaken"
<author>"Giuseppe Castagna"
<author>"Alain Frisch"
<title>"CDuce: a white-paper"
<conference>"PLANX-02"
<file>"planx.ps.gz"
]
]
in
do_biblio bib
;;
let fun facto (Int -> Int)
| 0 | 1 -> 1
| n -> n * (facto (n - 1))
in
facto 300;;
type Pos = 0--*;;
let fun abs (Int -> Pos)
| (x & Pos) -> x
| x -> 0 - x
in
abs (0-30);;
let fun wrap (0--100 -> 0--10)
| x & 0--10 -> x
| x -> wrap (x - 10)
in
wrap 67;;
type Expr =
(`add, Expr, Expr)
| (`mul, Expr, Expr)
| (`sub, Expr, Expr)
| (`div, Expr, Expr)
| Int;;
let fun eval ( Expr -> Int )
| (`add,x,y) -> eval x + eval y
| (`mul,x,y) -> eval x * eval y
| (`sub,x,y) -> eval x - eval y
| (`div,x,y) -> eval x / eval y
| n -> n
in
eval (`add, 10, (`add, 20, 5));;
......@@ -12,8 +12,16 @@ type Daughters = <daughters>[ Woman* ];;
let fun sort (MPerson -> Man ; FPerson -> Woman)
<person gender=g>[ n <children>[(mc::MPerson | fc::FPerson)*] ] ->
let tag = match g with 'F' -> `woman | 'M' -> `man in
let s = map mc with (x & MPerson) -> sort x in
let s = map mc with x -> sort x in
let d = map fc with x -> sort x in
<(tag)>[ n <sons>s <daughters>d ]
in sort(<person gender='F'>[ <name>["pippo"] <children>[ ]]);;
in sort(<person gender='F'>[
<name>["Veronique"]
<children>[
<person gender='F'>[
<name>["Ilaria"]
<children>[]
]
]
]);;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment