Coq最后一次出现的“Coq”;“典型”;必须有;A「;作为第一个论点

Coq最后一次出现的“Coq”;“典型”;必须有;A「;作为第一个论点,coq,Coq,我想检查extract函数的正确性,但Coq给了我一个错误 最后一次出现的“typ”必须将“A”作为“typ(list(string*json))”中的第一个参数 但是在OCaml(或Haskell)中,我可以用几乎相同的定义制作这样的GADT 键入'a foo=foo:int foo 实际上我不理解这个错误。这是什么意思?正如@AntonTrunov所说的,我通过这样更改类型成功地抑制了这个错误 Inductive json : Type := | Assoc : list (prod str

我想检查
extract
函数的正确性,但Coq给了我一个错误

最后一次出现的“typ”必须将“A”作为“typ(list(string*json))”中的第一个参数

但是在OCaml(或Haskell)中,我可以用几乎相同的定义制作这样的GADT

键入'a foo=foo:int foo


实际上我不理解这个错误。这是什么意思?

正如@AntonTrunov所说的,我通过这样更改类型成功地抑制了这个错误

Inductive json : Type :=
| Assoc : list (prod string json) -> json
| Bool : bool -> json
| Float : Q -> json
| Int : Z -> json
| List : list json -> json
| Null : unit -> json
| String : string -> json
| Tuple : list json -> json
| Variant : prod string (option json) -> json.

Inductive typ (A:Type) : Type :=
| TAssoc : typ (list (prod string json))
| TBool : typ bool 
| TFloat : typ Q 
| TInt : typ Z 
| TList : typ (list json)
| TNull : typ unit 
| TString : typ string 
| TTuple : typ (list json) 
| TVariant : typ (prod string (option json)).

Definition extract (A:Type) (j:json) (t:typ A) : option A :=
    match j,t with
    | Assoc x, TAssoc => Some x
    | Bool x, TBool => Some x
    | Float x, TFloat => Some x
    | Int x, TInt => Some x
    | List x, TList => Some x
    | String x, TString => Some x
    | Variant x, TVariant => Some x
    | _, _ => None
    end.

它起作用了

如果你能让你的代码编译到
extract
,那会有很大帮助。哦,那么错误消息是关于
typ
,而不是
extract
。您的意思可能是
归纳型类型->类型:=…
我认为在这种情况下应该很有用。@AntonTrunov谢谢!我已经把问题解决了!
Inductive typ : Type -> Type :=
| TAssoc : typ (list (prod string json))
| TBool : typ bool 
| TFloat : typ Q 
| TInt : typ Z 
| TList : typ (list json)
| TNull : typ unit 
| TString : typ string 
| TTuple : typ (list json) 
| TVariant : typ (prod string (option json)).