List Info

Thread: "ocaml_beginners"::[] Functor and type




"ocaml_beginners"::[] Functor and type
country flaguser name
United States
2007-09-18 16:41:10

Hi all,
From the following code,
-------------------------------------------------
module type SPACE_TYPE =
sig
type vecteur
val base : vecteur list
val fgen : vecteur -> int
val string_vecteur : vecteur -> string
end;;

module E3D_SPACE : SPACE_TYPE =
struct
type vecteur = E1 | E2 | E3
let base = [E1; E2; E3]
let fgen vector = 1
let string_vecteur vector = match vector with
E1 -> "e1"
| E2 -> "e2"
| E3 -> "e3"
end ;;
---------------------------------------------------
I'd like to define a module EnD_SPACE for a basis of n elements
[E1;E2;..;En].
I would like to write something like
------------------------------
module type Int_TYPE =
sig
val p : int
end

module EnD_SPACE = functor (N : Int_TYPE) ->
struct
type vecteur = E1 | E2 | .. ( with N.p )
let base = [E1; E2; ... ]
let fgen vector = 1 (idem)
let string_vecteur vector = match vector with
E1 -> "e1"
| E2 -> "e2"
.......
end ;;
---------------------
cause module EnD_SPACE = functor ( n : int ) -> ... is not accepted.
How can i define vecteur, base and string_vecteur ?
Thanks in advance,
Christophe.

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Yoga Groups

Exchange insights

with members of

the yoga community.

Re: "ocaml_beginners"::[] Functor and type
country flaguser name
United Kingdom
2007-09-20 12:17:28


Le 18 sept. 07 à 23:41, krom17 a écrit :

>; ---------------------------------------------------
> I'd like to define a module EnD_SPACE for a basis of n elements
> [E1;E2;..;En].
>; I would like to write something like
>; ------------------------------
> module type Int_TYPE =
> sig
> val p : int
> end
>
> module EnD_SPACE = functor (N : Int_TYPE) ->
> struct
> type vecteur = E1 | E2 | .. ( with N.p )
> let base = [E1; E2; ... ]
> let fgen vector = 1 (idem)
> let string_vecteur vector = match vector with
>; E1 -> "e1"
> | E2 -> "e2"
> .......
> end ;;
> ---------------------
> cause module EnD_SPACE = functor ( n : int ) -> ... is not accepted.
> How can i define vecteur, base and string_vecteur ?

Hi,

it seems you would need some camlp4... and I am not the man to help
you on this :(

Or else would you bother to define :

type vecteur = int
let base = [1;2;3;...]
?

V.

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )