类型错误:类型为 (string * terme) 列表的预期表达式,但收到类型为 ((terme -> terme) * (terme -> terme)) 列表的表达式

问题描述 投票:0回答:0

我遇到过这个错误,无法解决

type terme =
  | Var of string
  | Sym of string
  | Func of terme * terme

exception Echec

let rec sub v t = function 
  | Var v' when v = v' -> t
  | Func (t1, t2) -> Func (sub v t t1, sub v t t2)
  | t -> t
let rec occ_check v = function
  | Var v' when v'=v -> true
  | Func (t1,t2) -> occ_check v t1 || occ_check v t2
  | _ -> false

  let rec unif e (t1, t2) =
  match (t1, t2) with
  | Var v1, Var v2 when v1 = v2 -> e
  | Var v, t | t, Var v ->
      if List.mem_assoc v e then unif e (List.assoc v e, t)
      else if occ_check v t then raise Echec
      else (v, t) :: List.map (fun (t1, t2) -> (sub v t1, sub v t2)) e
  | Func (f1, a1), Func (f2, a2) ->
      let e' = unif e (f1, f2) in
      unif e' (a1, a2)
  | Sym s1, Sym s2 when s1 = s2 -> e
  | _ -> raise Echec

收到消息

This expression has type ((terme -> terme) * (terme -> terme)) list
but an expression was expected of type (string * terme) list
Type terme -> terme is not compatible with type string

我试过了

else (v, t) :: List.map (fun (s, t') -> (s, sub v t')) e
但仍然没有

ocaml
© www.soinside.com 2019 - 2024. All rights reserved.