List Info

Thread: "ocaml_beginners"::[] scope in sub-structure




"ocaml_beginners"::[] scope in sub-structure
country flaguser name
United States
2007-08-22 14:16:23

What are the rules for variable scope in sub-structures? I would like to
write:

------ A.ml -------
type t = string
let foo = 3

module M = struct
type t = t list (* this gives recursive type def error, I want t in "t
list" to refer to above t *)
let foo = foo + 3 (* get error, unrecognized identifier foo *)
end
------------------------

How can module M refer to t and foo in module A? Thanks.

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] scope in sub-structure
country flaguser name
United States
2007-08-22 14:35:41

On Wed, 22 Aug 2007, Ashish Agarwal wrote:

> What are the rules for variable scope in sub-structures? I would like to
> write:
>
> ------ A.ml -------
> type t = string
> let foo = 3
>
> module M = struct
> type t = t list (* this gives recursive type def error, I want t in "t
> list" to refer to above t *)
> let foo = foo + 3 (* get error, unrecognized identifier foo *)
> end
> ------------------------
>;
> How can module M refer to t and foo in module A? Thanks.

Unfortunately, something like:

type t' = t
type t = t' list

Martin

--
http://martin.jambon.free.fr

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] scope in sub-structure
country flaguser name
United States
2007-08-22 15:24:18

> Unfortunately, something like:
> type t' = t
> type t = t' list

That's unfortunate. The point of my sub-structure is that it specializes the
previous functions, so giving them the same name is really what I need. I
can rearrange some other way I guess.

[Non-text portions of this message have been removed]

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

It's Now Personal

Guides, news,

advice & more.

Featured Y! Groups

and category pages.

There is something

for everyone.

Yoga Groups

Exchange insights

with members of

the yoga community.

Re: "ocaml_beginners"::[] scope in sub-structure
country flaguser name
United Kingdom
2007-08-23 02:02:51

Hi

Le 22 août 07 à 21:16, Ashish Agarwal a écrit :

>; What are the rules for variable scope in sub-structures? I would
> like to
> write:
>
> ------ A.ml -------
> type t = string
> let foo = 3
>
> module M = struct
> type t = t list (* this gives recursive type def error, I want
> t in "t
> list" to refer to above t *)

> let foo = foo + 3 (* get error, unrecognized identifier foo *)
-->; are you sure for this 2nd error ? I can't reproduce it

Only the first one is a pb, solved by Martin's solution.

So this should not be a pb :

Le 22 août 07 à 22:24, Ashish Agarwal a écrit :

>; That's unfortunate. The point of my sub-structure is that it
> specializes the
> previous functions, so giving them the same name is really what I
> need. I
> can rearrange some other way I guess.

The functions can remain the same.

BTW if you're trying to do inheritance with modules you should soon
see that this can be a real mess...

--
Vincent Aravantinos
PhD Student - LIG - CAPP Team

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] scope in sub-structure
country flaguser name
United States
2007-08-23 08:37:48

> > let foo = foo + 3 (* get error, unrecognized identifier foo *)
> --> are you sure for this 2nd error ? I can't reproduce it

You are right. This works fine. I'm must have done something else when I got
the error. Thanks.

I'm not doing inheritance. It's a simple stream based line parser. Functions
in the main module take an extra parameter specifying the delimiter between
items on a line. The sub-module is a functor that takes in a delimiter as
parameter. Then all the functions within it don't have to be given the
delimiter.

[Non-text portions of this message have been removed]

__._,_.___
.

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

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