Re: syntax puzzle
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAMu2m2KjP3=wSFSC2cShR2qArrEyfuSXnbB02JE2e4FZFA2sjQ@mail.gmail.com> |
> 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:
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
>
>