Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
d85c61c0
Commit
d85c61c0
authored
Oct 05, 2007
by
Pietro Abate
Browse files
[r2002-11-11 20:01:29 by cvscast] Empty log message
Original author: cvscast Date: 2002-11-11 20:01:29+00:00
parent
7eefc5b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/overloading.cd
View file @
d85c61c0
type Person = FPerson | MPerson;;
type FPerson = <person gender =
['F']
>[ Name Children ];;
type MPerson = <person gender="M">[ Name Children];;
type FPerson = <person gender =
"F"
>[ Name Children
(Tel | Email)?
];;
type MPerson = <person gender="M">[ Name Children
(Tel | Email)?
];;
type Children = <children>[Person*];;
type Name = <name>[ PCDATA ];;
type Tel = <tel kind=?"home"|"work">['0'--'9'+ '-' '0'--'9'+];;
type Email = <email>[PCDATA '@' PCDATA];;
type Man = <man name=String>[ Sons Daughters ];;
type Woman = <woman name=String>[ Sons Daughters ];;
...
...
@@ -10,27 +12,44 @@ type Sons = <sons>[ Man* ];;
type Daughters = <daughters>[ Woman* ];;
let fun sort (MPerson -> Man ; FPerson -> Woman)
<person gender=g>[ <name>n <children>[(mc::MPerson | fc::FPerson)*]
] ->
<person gender=g>[ <name>n <children>[(mc::MPerson | fc::FPerson)*]
; _
] ->
let tag = match g with "F" -> `woman | "M" -> `man in
let s = map mc with x -> sort x in
let d = map fc with x -> sort x in
<(tag) name=n>[ <sons>s <daughters>d ]
;;
let base : Person =
<person gender="
F
">[
<name>"
Veroniqu
e"
<person gender="
M
">[
<name>"
Claud
e"
<children>[
<person gender="F">[
<name>"Ilaria"
<children>[]
]
]
<name>"Vronique"
<children>[
<person gender="F">[
<name>"Ilaria"
<children>[]
]
]
<tel> "314-1592654"
]
]
<tel kind="home"> "271-828182"
]
;;
sort base;;
let fun contact(Person->String)
| <person>[ _ _ ((<tel kind="work"> x) | (<email> x) | (<tel kind="home"> x))] -> x
| _ ->"no contact";;
(* compilation efficace avec _ a la place de person *)
let fun name (Person | Man | Woman -> String)
<person>[ <name>n ; _ ]
| <_ name=n>_ -> n;;
...
...
toplevel/toploop.ml
View file @
d85c61c0
...
...
@@ -37,9 +37,6 @@ let refill_buf buffer len =
done
;
!
i
with
|
End_of_file
->
print_newline
()
;
if
!
i
>
0
then
(
got_eof
:=
true
;
!
i
)
else
0
|
Exit
->
!
i
end
...
...
@@ -77,9 +74,13 @@ let loop =
first_line
:=
true
;
let
semicolon
=
ref
0
in
while
!
semicolon
<
2
do
let
c
=
Stream
.
next
input
in
if
c
=
'
;
'
then
incr
semicolon
else
semicolon
:=
0
try
let
c
=
Stream
.
next
input
in
if
c
=
'
;
'
then
incr
semicolon
else
semicolon
:=
0
with
|
End_of_file
->
if
!
first_line
then
exit
0
done
with
|
End_of_file
->
exit
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment