2016-04-11 21 views
0

ast.ml olarak, yapı aşağıdaki gibidir: Farklı model eşleme print_fieldsrec bahsedilen AncakOCaml model eşleme

let rec print_bean fmt = function 
    | Bool -> put fmt "%s" "bool" 
    | Int -> put fmt "%s" "int" 
    | TLr f -> put fmt "%s" "{"; print_fieldsrec fmt f ; put fmt "%s" "}" 
    | TId id -> put fmt "%s" id 
and print_fieldsrec fmt = function 
    | f :: fe -> print_field fmt f; put fmt "%s" "," ; print_fieldsrec fmt fe 
and print_field fmt = function 
    | FIe (id, beantype) -> put fmt "%s" id; put fmt "%s" ":"; print_bean fmt beantype 

:

printer.ml içinde
type beantype = 
    | Bool 
    | Int 
    | TLr of fieldsrec 
    | TId of ident 
and fieldsrec = { fields : field list } 
and field = 
    | FIe of (ident * beantype) 

i aşağıdaki gibi kullanmak

Error: This pattern matches values of type 'a list 
    but a pattern was expected which matches values of type 
    Bean_ast.fieldsrec 

Yazıcıyı nasıl değiştirebilirim.ml?

+2

'TLr' 'fieldsrec', bir liste değil. Belki de kalıbı '| TLr {fields = f}. – RichN

+0

Denedim, haklısın –

cevap

0

fieldsrec = { fields : field list } türüyle karıştırılmış görünüyorsunuz. Jeffrey'nin bunun yerine | Fields of field list'u kullanma tavsiyesini izlemelisiniz.

fieldsrec bir listesini içeren bir kaydıdır, bir liste değildir, bu yüzden

print_fieldsrec fmt = function f :: fe -> ... 

Adından da anlaşılacağı türüne sahip değil.

Ayrıca, yinelemeli print_fieldsrec için temel durumu da unuttunuz.