in ast.ml ist die Struktur unter:OCaml Musterübereinstimmung
type beantype =
| Bool
| Int
| TLr of fieldsrec
| TId of ident
and fieldsrec = { fields : field list }
and field =
| FIe of (ident * beantype)
in printer.ml, verwende ich es, wie unten:
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
jedoch gesagt, es die verschiedene Musterübereinstimmung in print_fieldsrec
Error: This pattern matches values of type 'a list
but a pattern was expected which matches values of type
Bean_ast.fieldsrec
Wie kann ich die printer.ml ändern?
'TLr' enthält eine' fields_rec', keine Liste. Ändere das Muster vielleicht auf '| TLr {Felder = f} '. – RichN
Ich habe versucht, Sie haben Recht –