List Info

Thread: "ocaml_beginners"::[] "*" in type




"ocaml_beginners"::[] "*" in type
country flaguser name
United States
2007-05-28 23:24:34

what is the meaning of "*"? thanks.

type stm =
SEQ of stm * stm
means stm followed by stm?

like in
# type exp =
CONST of int * int;;
how to write such a type?
1*1;;
?

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

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] "*" in type
country flaguser name
United Kingdom
2007-05-29 00:07:05

On Tuesday 29 May 2007 05:24:34 LianYang wrote:
> what is the meaning of "*"? thanks.
>
> type stm =
> SEQ of stm * stm
> means stm followed by stm?

A product type: "a * b" means the Cartesian product of the sets of values "a"
and "b".

For example, if "a = A1 | A2" and "b = B1 | B2" then "a * b" represents the
set of values containing:

(A1, B1)
(A1, B2)
(A2, B1)
(A2, B2)

> like in
> # type exp =
> CONST of int * int;;
> how to write such a type?
> 1*1;;

If you mean: how do I create a value of the type "int * int", then you write a
tuple, in this case a pair of two ints:

# (1, 2);;
- : int * int = (1, 2)

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

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] "*" in type
country flaguser name
United States
2007-05-29 02:01:25

> like in
> # type exp =
> CONST of int * int;;
> how to write such a type?
> 1*1;;
also, that type definition actually defines a Variant type so to
create a value of type exp, you should use the CONST constructor that
you has previusly defined:
# let b = CONST(2,3);;
val b : expr = CONST (2, 3)

2007/5/29, Jon Harrop < jon%40ffconsultancy.com">jonffconsultancy.com&gt;:
> On Tuesday 29 May 2007 05:24:34 LianYang wrote:
&gt; > what is the meaning of "*&quot;? thanks.
> >
>; > type stm =
> > SEQ of stm * stm
> > means stm followed by stm?
>;
> A product type: "a * b" means the Cartesian product of the sets of values
&gt; "a&quot;
> and "b&quot;.
>
> For example, if "a = A1 | A2" and "b = B1 | B2" then "a * b" represents the
> set of values containing:
>
> (A1, B1)
> (A1, B2)
> (A2, B1)
> (A2, B2)
>
> > like in
> > # type exp =
> > CONST of int * int;;
&gt; > how to write such a type?
&gt; > 1*1;;
&gt;
> If you mean: how do I create a value of the type "int * int", then you write
&gt; a
> tuple, in this case a pair of two ints:
&gt;
> # (1, 2);;
>; - : int * int = (1, 2)
>
> --
> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
>; The F#.NET Journal
> http://www.ffconsultancy.com/products/fsharp_journal/?e
&gt;

--
Pablo Polvorin

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] "*" in type
country flaguser name
United States
2007-05-29 04:41:21

Thank both of you!
1. Then, could i say, the star "*&quot; here is used to define tuple?

2. And it's used to represent tree structure, right?
type stm = SEQ of stm * stm

I'm asking this kind of thing because i'm writing the tiger compiler in
ocaml.

On 5/29/07, Pablo Polvorin < pablo.polvorin%40gmail.com">pablo.polvoringmail.com> wrote:
&gt;
> > like in
> > # type exp =
> > CONST of int * int;;
&gt; > how to write such a type?
&gt; > 1*1;;
&gt; also, that type definition actually defines a Variant type so to
> create a value of type exp, you should use the CONST constructor that
>; you has previusly defined:
> # let b = CONST(2,3);;
> val b : expr = CONST (2, 3)
>
> 2007/5/29, Jon Harrop < jon%40ffconsultancy.com">jonffconsultancy.com <jon%40ffconsultancy.com>>:
>;
> > On Tuesday 29 May 2007 05:24:34 LianYang wrote:
&gt; > > what is the meaning of "*&quot;? thanks.
> > >
>; > > type stm =
> > > SEQ of stm * stm
> > > means stm followed by stm?
>; >
>; > A product type: "a * b" means the Cartesian product of the sets of
> values
&gt; > "a&quot;
> > and "b&quot;.
> >
>; > For example, if "a = A1 | A2" and "b = B1 | B2" then "a * b" represents
> the
> > set of values containing:
> >
>; > (A1, B1)
> > (A1, B2)
> > (A2, B1)
> > (A2, B2)
> >
>; > > like in
> > > # type exp =
> > > CONST of int * int;;
&gt; > > how to write such a type?
&gt; > > 1*1;;
&gt; >
>; > If you mean: how do I create a value of the type "int * int", then you
> write
&gt; > a
> > tuple, in this case a pair of two ints:
&gt; >
>; > # (1, 2);;
>; > - : int * int = (1, 2)
> >
>; > --
> > Dr Jon D Harrop, Flying Frog Consultancy Ltd.
>; > The F#.NET Journal
> > http://www.ffconsultancy.com/products/fsharp_journal/?e
&gt; >
>;
> --
> Pablo Polvorin
>
>;
>

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

__._,_.___
.

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

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