2016-04-10 8 views
0

Schlag ist der ast.ml, alle ast.mli in gleicheFehler in OCaml Datenstrukturtyp

type ident = string 

type beantype = 
    | Bool 
    | Int 
    | { fields : field list } 
    | TId of ident 
and field = 
    (ident * beantype) 

in parser.mly, verwende ich die Felder als Liste

typespec : 
    | BOOL { Bool } 
    | INT { Int } 
    | LBRAK fields RBRAK { { fields = List.rev $2 } } 
    | IDENT { TId $1 } 

fields : 
    | fields COMMA field { $3 :: $1 } 

field : 
    | IDENT COLON typespec { ($1, $3) } 

es jedoch ist ein Fehler wie folgt:

ocamlc -c bean_ast.mli 
File "bean_ast.mli", line 6, characters 3-4: 
Error: Syntax error 
make: *** [bean_ast.cmi] Error 2 

Warum gibt es einen Fehler?

Antwort

4

Diese Erklärung:

type beantype = 
    | Bool 
    | Int 
    | { fields : field list } 
    | TId of ident 

ist in OCaml nicht gültig. Jede der Varianten benötigt eine Markierung, d. H. Eine großgeschriebene Kennung der Variante. Ihre dritte Variante hat keine.

Es ist derzeit auch nicht möglich, einen neuen Satztyp als Teil eines Variantentyps zu deklarieren.

Die folgende funktioniert:

type ident = string 
type beantype = 
    | Bool 
    | Int 
    | Fields of fieldrec 
    | Tid of ident 
and fieldrec = { fields: field list } 
and field = ident * beantype 

Persönlich folgt Ich könnte die Art erklären wie:

type ident = string 
type beantype = 
    | Bool 
    | Int 
    | Fields of field list 
    | Tid of ident 
and field = ident * beantype