* [Caml-list] Objects or modules ?
@ 2002-06-29 1:14 Nicolas FRANCOIS
2002-06-29 6:47 ` Chris Hecker
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Nicolas FRANCOIS @ 2002-06-29 1:14 UTC (permalink / raw)
To: Caml List
I'd like to make a library managing mathematical data structures, for
example integers, polynoms, fractions, and more if anyone is interested. I
started on the module point of view, mainly to learn how to use modules
and functors. So this is the structure I have :
Ordered_Ring : module managing basic rings operations
Rationnals : Num rationnals adapted to Ordered_Ring
Polynoms : functor taking an ordered ring S in argument to make a module
managing S[x]
Q_polynoms : polynoms over rationnals.
But I see things differently now, mainly because I realized S[x] is an
euclidian ring just as S is, so they should inherit the same module, and
have common operations ((extended) Euclide, square_free factorization...).
in fact I realized this when I started writing my second gcd function.
So my point of view is now :
Euclidian_Ring : Functor taking a ring signature (data structure, basic
operation + and *, link with Z and Q...), and constructing an euclidian
ring with tools.
Rationnals : Euclidian_Ring(Sig_Num)
Sig_Pol : Functor constructing an abstract polynom module sig
Polynom : functor constructing a ring S[x] provided a ring S
Do you think this plan is correct ? Should I translate it to objects ? Is
there some drawbacks using modules or objects ?
Thanks for reading.
\bye
--
Nicolas FRANCOIS
http://nicolas.francois.free.fr
A TRUE Klingon programmer does NOT comment his code
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Objects or modules ?
2002-06-29 1:14 [Caml-list] Objects or modules ? Nicolas FRANCOIS
@ 2002-06-29 6:47 ` Chris Hecker
2002-06-30 6:44 ` Blair Zajac
2002-06-29 10:22 ` Markus Mottl
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Chris Hecker @ 2002-06-29 6:47 UTC (permalink / raw)
To: Nicolas FRANCOIS, Caml List
>Do you think this plan is correct ? Should I translate it to objects ? Is
>there some drawbacks using modules or objects ?
This presentation by Xavier will get you started answering this question:
Objects and classes versus modules in Objective Caml
http://pauillac.inria.fr/~xleroy/talks/icfp99.ps.gz
Chris
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Objects or modules ?
2002-06-29 1:14 [Caml-list] Objects or modules ? Nicolas FRANCOIS
2002-06-29 6:47 ` Chris Hecker
@ 2002-06-29 10:22 ` Markus Mottl
2002-07-03 23:16 ` Nicolas FRANCOIS
2002-07-01 1:19 ` Nicolas FRANCOIS
2002-07-02 17:24 ` Francois Pottier
3 siblings, 1 reply; 8+ messages in thread
From: Markus Mottl @ 2002-06-29 10:22 UTC (permalink / raw)
To: Nicolas FRANCOIS; +Cc: Caml List
On Sat, 29 Jun 2002, Nicolas FRANCOIS wrote:
> I'd like to make a library managing mathematical data structures, for
> example integers, polynoms, fractions, and more if anyone is interested. I
> started on the module point of view, mainly to learn how to use modules
> and functors. So this is the structure I have :
You might also want to take a look at Christophe Raffalli's library for
formal and numerical calculus to grab a few ideas:
http://lama-d134.univ-savoie.fr/sitelama/Membres/pages_web/RAFFALLI/formel.html
Regards,
Markus Mottl
--
Markus Mottl markus@oefai.at
Austrian Research Institute
for Artificial Intelligence http://www.oefai.at/~markus
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Objects or modules ?
2002-06-29 6:47 ` Chris Hecker
@ 2002-06-30 6:44 ` Blair Zajac
0 siblings, 0 replies; 8+ messages in thread
From: Blair Zajac @ 2002-06-30 6:44 UTC (permalink / raw)
To: Chris Hecker; +Cc: Nicolas FRANCOIS (AKA El Bofo), Caml List
Chris Hecker wrote:
>
> >Do you think this plan is correct ? Should I translate it to objects ? Is
> >there some drawbacks using modules or objects ?
>
> This presentation by Xavier will get you started answering this question:
>
> Objects and classes versus modules in Objective Caml
> http://pauillac.inria.fr/~xleroy/talks/icfp99.ps.gz
What does the symbol [[ ]] mean in the paper?
It's used to describe closures
[[f(a)]] = [[f].code([[f], [[a]])
object method calls
[[o#m(a)]] = [[o]].methsuite(m)([[o]], [[a]])
Best,
Blair
--
Blair Zajac <blair@orcaware.com>
Web and OS performance plots - http://www.orcaware.com/orca/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Objects or modules ?
2002-06-29 1:14 [Caml-list] Objects or modules ? Nicolas FRANCOIS
2002-06-29 6:47 ` Chris Hecker
2002-06-29 10:22 ` Markus Mottl
@ 2002-07-01 1:19 ` Nicolas FRANCOIS
2002-07-02 17:24 ` Francois Pottier
3 siblings, 0 replies; 8+ messages in thread
From: Nicolas FRANCOIS @ 2002-07-01 1:19 UTC (permalink / raw)
To: Caml List
Thanks for the pointers. Exactly what I was looking for.
\bye
--
Nicolas FRANCOIS
http://nicolas.francois.free.fr
A TRUE Klingon programmer does NOT comment his code
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Objects or modules ?
2002-06-29 1:14 [Caml-list] Objects or modules ? Nicolas FRANCOIS
` (2 preceding siblings ...)
2002-07-01 1:19 ` Nicolas FRANCOIS
@ 2002-07-02 17:24 ` Francois Pottier
3 siblings, 0 replies; 8+ messages in thread
From: Francois Pottier @ 2002-07-02 17:24 UTC (permalink / raw)
To: Nicolas FRANCOIS, caml-list
On Sat, Jun 29, 2002 at 03:14:58AM +0200, Nicolas FRANCOIS wrote:
> I'd like to make a library managing mathematical data structures, for
> example integers, polynoms, fractions, and more if anyone is interested. I
> started on the module point of view, mainly to learn how to use modules
> and functors.
You may be interested in having a look at the FOC project's publications:
http://www.lip6.fr/reports/lip6.2000.014.html
http://calfor.lip6.fr/~foc/
They are writing a large library of mathematical structures in O'Caml.
I would recommend getting in touch with them for more information.
--
François Pottier
Francois.Pottier@inria.fr
http://pauillac.inria.fr/~fpottier/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Objects or modules ?
2002-06-29 10:22 ` Markus Mottl
@ 2002-07-03 23:16 ` Nicolas FRANCOIS
2002-07-05 0:02 ` Nicolas FRANCOIS
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas FRANCOIS @ 2002-07-03 23:16 UTC (permalink / raw)
To: caml-list
Le Sat, 29 Jun 2002 12:22:52 +0200 Markus Mottl <markus@oefai.at> a écrit
:
> You might also want to take a look at Christophe Raffalli's library for
> formal and numerical calculus to grab a few ideas:
>
> http://lama-d134.univ-savoie.fr/sitelama/Membres/pages_web/RAFFALLI/formel.html
OK, I got it. If I really understand this, this is a pre-project for FOC.
Am I right ?
Now that I adapted it to OCaml 3.04 (Streams not recognized by standard
OCaml now), I have a new problem : this is a definition for a quotient
ring (there's a similar one for a quotient field in case the ideal is
primitive) ;
(in algebra.mli)
module Quotient :
functor(R : Euclidian_Ring) ->
functor(Elt : One_element with type elem = R.elem) ->
Ring with type elem = R.elem
(in algebra.ml)
module Quotient =
functor (R : Euclidian_Ring) ->
functor (Elt : One_element with type elem = R.elem) ->
struct
type elem = R.elem
let zero = R.zero
let one = R.one
let t_of_int = R.t_of_int
let (++) = R.(++)
let (--) = R.(--)
let ( ** ) = R.( ** )
let (==) a b = R.(==) (R.(mod) (R.(--) a b) Elt.elt) R.zero
let opp = R.opp
let normalize x = R.(mod) (R.normalize x) Elt.elt
let print x = R.print (normalize x)
let write ch x = R.write ch (normalize x)
let parse = R.parse
let read = R.read
let write_bin ch x = R.write_bin ch (normalize x)
let read_bin = R.read_bin
let conjugate = R.conjugate
end
I'd like to use this functor to create a ring Z/pZ, providing a (possibliy
prime) integer p. My problem is : what is the correct way to use this ?
Thanks for reading.
\bye
--
Nicolas FRANCOIS
http://nicolas.francois.free.fr
A TRUE Klingon programmer does NOT comment his code
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Objects or modules ?
2002-07-03 23:16 ` Nicolas FRANCOIS
@ 2002-07-05 0:02 ` Nicolas FRANCOIS
0 siblings, 0 replies; 8+ messages in thread
From: Nicolas FRANCOIS @ 2002-07-05 0:02 UTC (permalink / raw)
To: caml-list
Le Thu, 4 Jul 2002 01:16:11 +0200 Nicolas FRANCOIS (AKA El Bofo)
<nicolas.francois@free.fr> a écrit :
> Le Sat, 29 Jun 2002 12:22:52 +0200 Markus Mottl <markus@oefai.at> a
> écrit:
>
> > You might also want to take a look at Christophe Raffalli's library
> > for formal and numerical calculus to grab a few ideas:
> >
> > http://lama-d134.univ-savoie.fr/sitelama/Membres/pages_web/RAFFALLI/formel.html
>
> OK, I got it. If I really understand this, this is a pre-project for
> FOC. Am I right ?
>
> Now that I adapted it to OCaml 3.04 (Streams not recognized by standard
> OCaml now), I have a new problem : this is a definition for a quotient
> ring (there's a similar one for a quotient field in case the ideal is
> primitive) ;
>
> (in algebra.mli)
> module Quotient :
> functor(R : Euclidian_Ring) ->
> functor(Elt : One_element with type elem = R.elem) ->
> Ring with type elem = R.elem
>
> (in algebra.ml)
> module Quotient =
> functor (R : Euclidian_Ring) ->
> functor (Elt : One_element with type elem = R.elem) ->
> struct
> type elem = R.elem
> let zero = R.zero
> let one = R.one
> let t_of_int = R.t_of_int
> let (++) = R.(++)
> let (--) = R.(--)
> let ( ** ) = R.( ** )
> let (==) a b = R.(==) (R.(mod) (R.(--) a b) Elt.elt) R.zero
> let opp = R.opp
> let normalize x = R.(mod) (R.normalize x) Elt.elt
> let print x = R.print (normalize x)
> let write ch x = R.write ch (normalize x)
> let parse = R.parse
> let read = R.read
> let write_bin ch x = R.write_bin ch (normalize x)
> let read_bin = R.read_bin
> let conjugate = R.conjugate
> end
>
> I'd like to use this functor to create a ring Z/pZ, providing a
> (possibliy prime) integer p. My problem is : what is the correct way to
> use this ?
OK, I found a way :
(file essai.ml)
open Algebra
module Five : (One_element with type elem = Ring_MZ.elem) =
struct
type elem = Ring_MZ.elem
let elt = Ring_MZ.t_of_int 5
end
open Five
module Z5Z = Quotient_prime (Ring_MZ) (Five)
open Polynomial
module P = Make(Z5Z)
open P
let p1 = monome (Z5Z.t_of_int 8) 0
++ monome (Z5Z.t_of_int 4) 1
++ monome (Z5Z.t_of_int 1) 2;;
let p2 = monome (Z5Z.t_of_int 3) 1
++ monome (Z5Z.t_of_int 1) 12
++ monome (Z5Z.t_of_int 2) 14;;
print (p1 ** (p2 // p1) ++ (p2 mod p1) -- p2)
(The end for the ones how know the package Formel)
Is there a way to do things simpler ?
\bye
--
Nicolas FRANCOIS
http://nicolas.francois.free.fr
A TRUE Klingon programmer does NOT comment his code
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2002-07-04 23:54 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-29 1:14 [Caml-list] Objects or modules ? Nicolas FRANCOIS
2002-06-29 6:47 ` Chris Hecker
2002-06-30 6:44 ` Blair Zajac
2002-06-29 10:22 ` Markus Mottl
2002-07-03 23:16 ` Nicolas FRANCOIS
2002-07-05 0:02 ` Nicolas FRANCOIS
2002-07-01 1:19 ` Nicolas FRANCOIS
2002-07-02 17:24 ` Francois Pottier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox