| Newsgroups |
gmane.comp.lang.ocaml.beginners |
| Message-ID |
<[email protected]> |
On Mon, Jun 22, 2015 at 10:18:37AM -0400, Ashish Agarwal [email protected] [ocaml_beginners] wrote:
> > Am I really required to have an actual name after the 'of'?
>
> Yes, but it it not because you are using it within a variant. In general,
> record types in OCaml have to be defined. There are no values of type
> {a:int} unless you first define a type t = {a:int}. For example, this is
> wrong:
I see. It seems like a bizarre language restriction, but I suppose
I'll have to live with it. One of the joys of OCaml was always that it
*didn't* have this kind of restriction.
-- hendrik
>
> let f (x : {a:int}) = x.a + 1
>
> You must instead do:
>
> type t = {a:int}
> let f (x:t) = x.a + 1
>
>
> On Thu, Jun 18, 2015 at 3:47 PM, Hendrik Boom [email protected]
> [ocaml_beginners] <[email protected]> wrote:
>
> >
> >
> > Whi do I get a syntax error
> >
> > hendrik@notlookedfor:~/dv/lang/experiment/autometa$ ocamlc ko.ml -o ko
> > File "ko.ml", line 4, characters 10-11:
> > Error: Syntax error
> >
> > for the following code:
> >
> > hendrik@notlookedfor:~/dv/lang/experiment/autometa$ cat ko.ml
> >
> > type exp =
> > (* type constructors *)
> > Pity of {source : exp; target : exp}
> > ;;
> > hendrik@notlookedfor:~/dv/lang/experiment/autometa$
> >
> > bot not:
> >
> > hendrik@notlookedfor:~/dv/lang/experiment/autometa$ ocamlc ok.ml -o ok
> > hendrik@notlookedfor:~/dv/lang/experiment/autometa$
> >
> > for this code:?
> >
> > hendrik@notlookedfor:~/dv/lang/experiment/autometa$ cat ok.ml
> >
> > type exp =
> > (* type constructors *)
> > Pity of xxx
> > and xxx = {source : exp; target : exp}
> > ;;
> > hendrik@notlookedfor:~/dv/lang/experiment/autometa$
> >
> > Am I really required to have an actual name after the 'of'? I haven't
> > noticed a restriction like that anywhere else in the language.
> >
> > I suspect something else is going on, but I'm at a loss to know what.
> >
> > -- hendrik
> >
> >