coq-ceres icon indicating copy to clipboard operation
coq-ceres copied to clipboard

Deserialize: nullary constructors cannot be numbers

Open liyishuai opened this issue 5 years ago • 3 comments

Is it a bug or feature?

Instance Deserialize__unit : Deserialize unit :=
  Deser.match_con "unit type" [("204", tt)] [].

Goal (from_string "204" = inl
        (DeserError [ ]
           ("could not read type '" ++ "unit type" ++ "', " ++
            "unexpected atom (expected list or nullary constructor name)"))).
Proof. reflexivity. Qed.

liyishuai avatar Jan 11 '20 18:01 liyishuai

I'd classify that as working as expected, but it might also be a good idea to generalize match_con a little. At the same time, the match_con stuff is really meant to be used in a very formulaic manner entirely derived from the type declaration. If you want to have any say in the encoding, you might want to just pattern-match on the S-expression directly in this definition.

Lysxia avatar Jan 11 '20 20:01 Lysxia

Yea I can live with this feature, provided documentation.

liyishuai avatar Jan 12 '20 06:01 liyishuai

Sadly, generalizing match_con to allow arbitrary atoms as constructor tags breaks the current API. I hoped coercions would smooth this out but they don't. We could have the generalized version as a separate function, but I still feel like this is a rather odd use case. Instead, I can add some documentation about defining parsers by manual pattern-matching.

Lysxia avatar Feb 07 '20 19:02 Lysxia