List Info

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




Re: "ocaml_beginners"::[] What's difference between both types ?
country flaguser name
United States
2007-05-07 23:01:59

Hi Pablo,

Follow explanation kindly provided by you
and Dr. Jon, I realize a source of my problem.
which my understanding of type and value is mixed.
Below you may see what I was confused...

# let al= [1, 'A']
type tuoed= { x: int; y: char }
let bm= { x= 1; y= 'A' } ;;

val al : (int * char) list = [(1, 'A')]
type tuoed = { x : int; y : char; }
val bm : tuoed = {x = 1; y = 'A'}

# bm.x = fst (List.hd al) ;;
- : bool = true

# bm.y == snd (List.hd al) ;;
- : bool = true

Type tuoed and type (int * char) list are
different, but both of their element are
the same, so actually my purpose is to
compare the contents of different types.

--- In ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com, "Pablo Polvorin"
<pablo.polvorin...> wrote:
&gt;
> 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?&quot; ?.
>
> 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.
&gt;
> 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
&gt; it.
>
> regards
>
> --
> Pablo Polvorin
>

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] What's difference between both types ?
country flaguser name
France
2007-05-08 03:25:24

LE MARDI 08 MAI 2007 à 04:01 +0000, LORENZO A éCRIT :
> TYPE TUOED= { X: INT; Y: CHAR }

>; TYPE TUOED AND TYPE (INT * CHAR) LIST ARE
> DIFFERENT, BUT BOTH OF THEIR ELEMENT ARE
> THE SAME, SO ACTUALLY MY PURPOSE IS TO
> COMPARE THE CONTENTS OF DIFFERENT TYPES.

THE TYPE (INT * CHAR) LIST IS MUCH FURTHER FROM THE TYPE TUOED THAN THE
TYPE (INT * CHAR) AS IN

# LET CN = (1,'A');;

AND THEN YOU HAVE :

# BM.X = FST CN ;;
- : BOOL = TRUE

# BM.Y == SND CN ;;
- : BOOL = TRUE

OR MAYBE I'M MISUNDERSTANDING WHAT YOU'RE TRYING TO DO.
BUT INTERNALLY A TUOED AND A (INT*CHAR) GOT EXACTLY THE SAME
REPRESENTATION WHILE THERE IS ONE MORE INDIRECTION LEVEL FOR THE
(INT*CHAR) LIST.

MATHIAS

__._,_.___
.

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

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