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
f9acf044
Commit
f9acf044
authored
Oct 05, 2007
by
Pietro Abate
Browse files
[r2004-03-12 18:05:46 by beppe] Changed some typos and presentation
Original author: beppe Date: 2004-03-12 18:05:46+00:00
parent
fce496ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
web/manual/interface.xml
View file @
f9acf044
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<page
name=
"interfac
ing_
ocaml"
>
<page
name=
"
manual_
interfac
ewith
ocaml"
>
<title>
Interfacing CDuce with OCaml
</title>
<title>
Interfacing CDuce with OCaml
</title>
<box
title=
"Introduction"
link=
"intro"
>
<box
title=
"Introduction"
link=
"intro"
>
<p>
<p>
When you have to write a
big
program you
always
need to manage some
When you have to write a
large
program you
often
need to manage some
persistent data
s
. A really elegant and widespread technic, to fulfill
persistent data. A really elegant and widespread technic, to fulfill
this goal, is to use XML based documents. And a really safe and robust
this goal, is to use XML based documents. And a really safe and robust
way to treat XML files is to write a small program in CDuce. In this,
way to treat XML files is to write a small program in CDuce. In this,
document, we will
present a way to call CDuce functions from OCaml to
section, we
present a way to call CDuce functions from OCaml to
let you
couple the power of CDuce with the power of OCaml.
couple the power of CDuce with the power of OCaml.
</p>
</p>
<p>
<p>
This page explains how to write an interface file between CDuce and
This page explains how to write an interface file between CDuce and
OCaml and call CDuce code from OCaml
one
.
OCaml and call CDuce code from OCaml
programs
.
</p>
</p>
</box>
</box>
...
@@ -26,7 +26,7 @@ OCaml and call CDuce code from OCaml one.
...
@@ -26,7 +26,7 @@ OCaml and call CDuce code from OCaml one.
<p>
<p>
As you have probably seen CDuce uses regular expression based
As you have probably seen CDuce uses regular expression based
pattern-matching. This feature, combined with others, makes CDuce
pattern-matching. This feature, combined with others, makes CDuce
translation to OCaml a bit hard. That
'
s why you are asked to provide an
translation to OCaml a bit hard. That
i
s why you are asked to provide an
OCaml interface file to help the CDuce compiler in producing needed code
OCaml interface file to help the CDuce compiler in producing needed code
to let you call CDuce from your ML programs.
to let you call CDuce from your ML programs.
</p>
</p>
...
@@ -37,23 +37,23 @@ want to export from CDuce code.
...
@@ -37,23 +37,23 @@ want to export from CDuce code.
</p>
</p>
<p>
<p>
By
example, consider the following CDuce code, written in file
foo.cd
:
For
example, consider the following CDuce code, written in file
<code>
foo.cd
</code>
:
</p>
</p>
<sample>
<![CDATA[
<sample>
<![CDATA[
type
%%
ML_int
%%
= -1073741824 -- 1073741823
type ML_int = -1073741824 -- 1073741823
let
%%f%%
(
%%
Int
%%
->
%%
ML_int
%%
)
let
f
( Int ->
ML_int )
%%x%%
&
%%
ML_int
%%
->
%%x%%
x
&
ML_int ->
x
|
%%_%%
-> raise "Overflow"
|
_
-> raise "Overflow"
]]>
</sample>
]]>
</sample>
<p>
<p>
And now the OCaml code in file, foo.mli:
And now the OCaml code in file,
<code>
foo.mli
</code>
(we use the blue color to highlight Ocaml code)
:
</p>
</p>
<sample>
<![CDATA[
<sample>
<![CDATA[
val
%%f%%
:
%%
int
%%
->
%%
int
%%
$$
val
f
: int ->
int
$$
]]>
</sample>
]]>
</sample>
<p>
<p>
...
@@ -62,8 +62,8 @@ you are free to call it from any of your OCaml programs, as in:
...
@@ -62,8 +62,8 @@ you are free to call it from any of your OCaml programs, as in:
</p>
</p>
<sample>
<![CDATA[
<sample>
<![CDATA[
let () =
$$
let () =
if Foo.
f
8 <>
8 then failwith "Error"
if Foo.
$${{f}}$$
8 <>
8 then failwith "Error"
$$
]]>
</sample>
]]>
</sample>
<p>
<p>
...
@@ -72,9 +72,9 @@ Note that there are two rules to respect when creating your interface file:
...
@@ -72,9 +72,9 @@ Note that there are two rules to respect when creating your interface file:
<ul>
<ul>
<li>
<li>
Every function defined in your OCaml file (
<code>
.mli
</code>
) has to
Every function defined in your OCaml file (
<code>
.mli
</code>
) has to
be defined in your CDuce file. Whereas the opposite is
absolutely
not
be defined in your CDuce file. Whereas the opposite is not
ne
eded (
you can have much more functions in your CDuce file than in
ne
cessary:
you can have much more functions in your CDuce file than in
your OCaml
one)
.
your OCaml
interface, only the latter are exported but the module
.
</li>
</li>
<li>
<li>
Every function defined in your OCaml file has to be a supertype of your
Every function defined in your OCaml file has to be a supertype of your
...
@@ -97,15 +97,15 @@ you just have to follow the translation function, <code>T</code>, given by:
...
@@ -97,15 +97,15 @@ you just have to follow the translation function, <code>T</code>, given by:
</p>
</p>
<sample>
<![CDATA[
<sample>
<![CDATA[
T(
%%
bool
%%
) =
%%
Bool
%%
T(
$$
bool
$$
) = Bool
T(
%%
char
%%
) =
%%
Char
%%
T(
$$
char
$$
) = Char
T(
%%
int
%%
) = -1073741824 -- 1073741823
T(
$$
int
$$
) = -1073741824 -- 1073741823
T(
%%
string
%%
) =
%%
Latin1
%%
T(
$$
string
$$
) = Latin1
T(
%%
unit
%%
) =
%%[]%%
T(
$$
unit
$$
) =
[]
T(%%t
->
u%%) = T(%%t%%) -> T(%%u%%)
T(
$$
%%t
%%$$ $$->
$$ $$%%
u%%
$$
) = T(
$$
%%t%%
$$
) -> T(
$$
%%u%%
$$
)
T(
%%A%%
) = `A
T(
$$A$$
) = `A
T(
%%
A of t%%) = ( `A, T(%%t%%) )
T(
$$
A of
$$ $$%%
t%%
$$
) = ( `A, T(
$$
%%t%%
$$
) )
T(
%%
{ u :
t }%%
) = { u : T(%%t%%) } or {| u : T(%%t%%) |}
T(
$$
{ u :
$$ $$%%t%%$$ $$}$$
) = { u : T(
$$
%%t%%
$$
) } or {| u : T(
$$
%%t%%
$$
) |}
(depends on if it stands for a function argument or a return value).
(depends on if it stands for a function argument or a return value).
]]>
</sample>
]]>
</sample>
...
...
web/site.cd
View file @
f9acf044
...
@@ -78,6 +78,10 @@ let highlight (String -> [ (Char | H:Xstrong | H:Xi)* ] )
...
@@ -78,6 +78,10 @@ let highlight (String -> [ (Char | H:Xstrong | H:Xi)* ] )
[
<strong
class=
"highlight"
>
[
<i>
h]; highlight rest ]
[
<strong
class=
"highlight"
>
[
<i>
h]; highlight rest ]
| [ '{{' h ::(Char *?) '}}' ; rest ] ->
| [ '{{' h ::(Char *?) '}}' ; rest ] ->
[
<strong
class=
"highlight"
>
h; highlight rest ]
[
<strong
class=
"highlight"
>
h; highlight rest ]
| [ '$$%%' h ::(Char *?) '%%$$' ; rest ] ->
[
<strong
class=
"ocaml"
>
[
<i>
h]; highlight rest ]
| [ '$$' h ::(Char *?) '$$' ; rest ] ->
[
<strong
class=
"ocaml"
>
h; highlight rest ]
| [ '%%' h ::(Char *?) '%%' ; rest ] ->
| [ '%%' h ::(Char *?) '%%' ; rest ] ->
[
<i>
h; highlight rest ]
[
<i>
h; highlight rest ]
| [ c; rest ] -> [ c; highlight rest ]
| [ c; rest ] -> [ c; highlight rest ]
...
@@ -182,6 +186,9 @@ p {
...
@@ -182,6 +186,9 @@ p {
pre {
pre {
margin: 1ex 1em 0 1em;
margin: 1ex 1em 0 1em;
}
}
strong.ocaml{
color: #333b8e;
}
strong.highlight {
strong.highlight {
color: #FF0000;
color: #FF0000;
}
}
...
...
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