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"?>
<page
name=
"interfac
ing_
ocaml"
>
<page
name=
"
manual_
interfac
ewith
ocaml"
>
<title>
Interfacing CDuce with OCaml
</title>
<box
title=
"Introduction"
link=
"intro"
>
<p>
When you have to write a
big
program you
always
need to manage some
persistent data
s
. A really elegant and widespread technic, to fulfill
When you have to write a
large
program you
often
need to manage some
persistent data. A really elegant and widespread technic, to fulfill
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,
document, we will
present a way to call CDuce functions from OCaml to
let you
couple the power of CDuce with the power of OCaml.
section, we
present a way to call CDuce functions from OCaml to
couple the power of CDuce with the power of OCaml.
</p>
<p>
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>
</box>
...
...
@@ -26,7 +26,7 @@ OCaml and call CDuce code from OCaml one.
<p>
As you have probably seen CDuce uses regular expression based
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
to let you call CDuce from your ML programs.
</p>
...
...
@@ -37,23 +37,23 @@ want to export from CDuce code.
</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>
<sample>
<![CDATA[
type
%%
ML_int
%%
= -1073741824 -- 1073741823
type ML_int = -1073741824 -- 1073741823
let
%%f%%
(
%%
Int
%%
->
%%
ML_int
%%
)
%%x%%
&
%%
ML_int
%%
->
%%x%%
|
%%_%%
-> raise "Overflow"
let
f
( Int ->
ML_int )
x
&
ML_int ->
x
|
_
-> raise "Overflow"
]]>
</sample>
<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>
<sample>
<![CDATA[
val
%%f%%
:
%%
int
%%
->
%%
int
%%
$$
val
f
: int ->
int
$$
]]>
</sample>
<p>
...
...
@@ -62,8 +62,8 @@ you are free to call it from any of your OCaml programs, as in:
</p>
<sample>
<![CDATA[
let () =
if Foo.
f
8 <>
8 then failwith "Error"
$$
let () =
if Foo.
$${{f}}$$
8 <>
8 then failwith "Error"
$$
]]>
</sample>
<p>
...
...
@@ -72,9 +72,9 @@ Note that there are two rules to respect when creating your interface file:
<ul>
<li>
Every function defined in your OCaml file (
<code>
.mli
</code>
) has to
be defined in your CDuce file. Whereas the opposite is
absolutely
not
ne
eded (
you can have much more functions in your CDuce file than in
your OCaml
one)
.
be defined in your CDuce file. Whereas the opposite is not
ne
cessary:
you can have much more functions in your CDuce file than in
your OCaml
interface, only the latter are exported but the module
.
</li>
<li>
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:
</p>
<sample>
<![CDATA[
T(
%%
bool
%%
) =
%%
Bool
%%
T(
%%
char
%%
) =
%%
Char
%%
T(
%%
int
%%
) = -1073741824 -- 1073741823
T(
%%
string
%%
) =
%%
Latin1
%%
T(
%%
unit
%%
) =
%%[]%%
T(%%t
->
u%%) = T(%%t%%) -> T(%%u%%)
T(
%%A%%
) = `A
T(
%%
A of t%%) = ( `A, T(%%t%%) )
T(
%%
{ u :
t }%%
) = { u : T(%%t%%) } or {| u : T(%%t%%) |}
T(
$$
bool
$$
) = Bool
T(
$$
char
$$
) = Char
T(
$$
int
$$
) = -1073741824 -- 1073741823
T(
$$
string
$$
) = Latin1
T(
$$
unit
$$
) =
[]
T(
$$
%%t
%%$$ $$->
$$ $$%%
u%%
$$
) = T(
$$
%%t%%
$$
) -> T(
$$
%%u%%
$$
)
T(
$$A$$
) = `A
T(
$$
A of
$$ $$%%
t%%
$$
) = ( `A, 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).
]]>
</sample>
...
...
web/site.cd
View file @
f9acf044
...
...
@@ -78,6 +78,10 @@ let highlight (String -> [ (Char | H:Xstrong | H:Xi)* ] )
[
<strong
class=
"highlight"
>
[
<i>
h]; highlight rest ]
| [ '{{' h ::(Char *?) '}}' ; 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 ] ->
[
<i>
h; highlight rest ]
| [ c; rest ] -> [ c; highlight rest ]
...
...
@@ -182,6 +186,9 @@ p {
pre {
margin: 1ex 1em 0 1em;
}
strong.ocaml{
color: #333b8e;
}
strong.highlight {
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