q6.cd 2.21 KB
Newer Older
1
(*********function *********)
2
let fun count_bad([Any*]->Int)
3
	  [] -> 0
4
	| [_;t] -> 1+count(t);;
5

6
7
8
9
10
11
12
13
(* tail recursive definition *)

let fun count(x : [Any*]) : Int =
  let tr_count((Int,[Any*]) -> Int)
        |  (n,[]) -> n
        |  (n,[_;t]) -> tr_count(n+1,t)
   in tr_count(0,x)

14
15
(***************************)

16
17
18
19
20
(*****************************************************************
For each book that has at least one author, 
list the title and first two authors, 
and an empty "et-al" element if the book has additional authors.
******************************************************************)
21
22
23
24
25
26
27
28
let q6x=
<bib>
select 
  <book>
       ([b]/<title>_ @ 
           (match ([b]/<author>_) with 
                 | [a b  _+ ] ->[a b] @ [<et-al>[]]
		 | a ->a ) )    
29
from b in [doc]/<book>[_* Author _*];;
30
31

       
32
33
let q6p=
<bib>
34
select <book>[t  !a  !(if etal=[] then [] else [<et-al>[]])]
35
from <bib>[b::Book*] in [doc],
36
     <book>[t&Title a::(Author Author) etal::Author* ;_] in b;;
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

(* le typage est differents entre q6x et q6p:
on a pour q6x:
 <bib {| |}>[ <book {| |}>[ X1 X2 | X1 X2 X2 | X1 X2 X2
                                   <et-al {| |}>[  ] | X1 ]* ] where
          X1 = <title>[ Char* ] and
          X2 = <author>[ Last First ]
et pour q6p:
	  <bib {| |}>[ <book {| |}>[ Title Author | Title Author Author |
                                   Title Author Author X1 | Title Author X1 ]* ] where
          X1 = <et-al {| |}>[  ]

Dans le premier cas on a soit 
+ Title Author               = Ok
+ Title Author Author        = Ok
+ Title Author Author Et-aL  = Ok
+ Title                      = pas possible d etre dans ce cas 
                               avec la condition, mais le typage ne peut le
			       detecter

Dans le deuxieme cas on a soit:
+ Title Author	             =ok
+ Title Author Author        =ok
+ Title Author Author Et-aL  =ok
+ Title Author Et-al	     =ok pas possible aussi mais vient du if 


il est rigolo de remarquer que pour cqlx on sait qu on aura pas de Title Author
Et-al et qu en cqlp on sait qu on aura pas de Title tout court

q6x n est pas entierement ecrit en cqlx puisqu on se sert de patterns
patterns qu on pourrait utilise en cqlp et on aurait un type plus fin, mais une
expression plus longue.

*)