(* This file is free software, part of dolmen. See file "LICENSE" for more information *) (* Extended views *) (* ************************************************************************* *) module Assoc(V : Dolmen_intf.View.TFF.S) = struct let rec ty_left_assoc top_head = function | [] -> [] | (t :: r) as args -> begin match V.Ty.view ~expand:false t with | App(h, h_args) when top_head h -> ty_left_assoc top_head (h_args @ r) | _ -> args end let ty_right_assoc top_head args = let rec aux top_head = function | [] -> [] | (t :: r) as rev_args -> begin match V.Ty.view ~expand:false t with | App(h, h_args) when top_head h -> aux top_head (List.rev_append h_args r) | _ -> List.rev rev_args end in aux top_head (List.rev args) let rec term_left_assoc top_head = function | [] -> [] | (t :: r) as args -> begin match V.Term.view t with | App(h, _, h_args) when top_head h -> term_left_assoc top_head (h_args @ r) | _ -> args end let term_right_assoc top_head args = let rec aux top_head = function | [] -> [] | (t :: r) as rev_args -> begin match V.Term.view t with | App(h, _, h_args) when top_head h -> aux top_head (List.rev_append h_args r) | _ -> List.rev rev_args end in aux top_head (List.rev args) let term_chainable top_head args = let rec aux top_head acc = function | [] -> Some (List.rev acc) | t :: r -> begin match V.Term.view t with | App(h, _, [a; b]) when top_head h -> begin match acc with | [] -> aux top_head [b; a] r | x :: _ -> if V.Term.equal x a then aux top_head (b :: acc) r else None end | _ -> None end in aux top_head [] args end