Coq最后一次出现的“ typ”必须具有“ A”作为第一个参数

时间:2018-06-23 09:40:59

标签: coq

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函数的正确性,但是Coq给我一个错误,

Last occurrence of "typ" must have "A" as 1st argument in "typ (list (string * json))".

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

type 'a foo = Foo : int foo

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

1 个答案:

答案 0 :(得分:0)

就像@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)).

有效!