List Info

Thread: "ocaml_beginners"::[] What's difference between both types ?




"ocaml_beginners"::[] What's difference between both types ?
country flaguser name
United States
2007-05-06 02:37:29

Hello All,

I am confused with practice for
tuple within list and record, such as

# [1, "hello, ", 'A', 3.4] ;;
- : (int * string * char * float) list
= [(1, "hello, ", 'A', 3.4)]

# type tueod = { w: int; x: string; y: char; z: float } ;;
type tueod = { w : int; x : string; y : char; z : float; }

# { w= 1; x= "hello, "; y= 'A'; z= 3.4 } ;;
- : tueod = {w = 1; x = "hello, "; y = 'A'; z = 3.4}

Are the both types the same thing,
I don't know if OCaml compiler can do
test for user-customized type ?

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] What's difference between both types ?
country flaguser name
United States
2007-05-06 04:01:16

Hi Lorenzo,
i am dont sure if i understand correctly you question, what you mean for
"Are the both types the same thing, same thing?" ?.

The first is a list of tuples, that contains only one tuple. A tuple always
contain a fixed number of values, which may be of different types.

The second is a record, which is basically a tuple with named fields.
Because it is a record,you have to explicitly define that type before using
it.

regards

2007/5/6, LORENZO < arniwarp%40yahoo.com.tw">arniwarpyahoo.com.tw>:
>
>; Hello All,
>;
> I am confused with practice for
> tuple within list and record, such as
>
> # [1, "hello, ", 'A', 3.4] ;;
> - : (int * string * char * float) list
>; = [(1, "hello, ", 'A', 3.4)]
&gt;
> # type tueod = { w: int; x: string; y: char; z: float } ;;
> type tueod = { w : int; x : string; y : char; z : float; }
>
> # { w= 1; x= "hello, "; y= 'A'; z= 3.4 } ;;
> - : tueod = {w = 1; x = "hello, "; y = 'A'; z = 3.4}
>;
> Are the both types the same thing,
&gt; I don't know if OCaml compiler can do
> test for user-customized type ?
>
>
>

--
Pablo Polvorin

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

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] What's difference between both types ?
country flaguser name
United Kingdom
2007-05-06 17:04:57

On Sunday 06 May 2007 08:37, LORENZO wrote:
&gt; Hello All,
>;
> I am confused with practice for
> tuple within list and record, such as
>
> # [1, "hello, ", 'A', 3.4] ;;
> - : (int * string * char * float) list
>; = [(1, "hello, ", 'A', 3.4)]
&gt;
> # type tueod = { w: int; x: string; y: char; z: float } ;;
> type tueod = { w : int; x : string; y : char; z : float; }
>
> # { w= 1; x= "hello, "; y= 'A'; z= 3.4 } ;;
> - : tueod = {w = 1; x = "hello, "; y = 'A'; z = 3.4}
>;
> Are the both types the same thing,

The are two different types, the former is a list of tuples whereas the latter
is a record. The types have different properties. For example, a list may
contain many elements so the following value is of the same type:

# [1, "hello, ", 'A', 3.4; 2, "world", 'B', 7.2];;
- : (int * string * char * float) list = ...

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?e

__._,_.___
.

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

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