mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
More functorization
This commit is contained in:
parent
4852891e6c
commit
2f7059c1ac
@ -31,9 +31,36 @@ module type Backend = sig
|
||||
val print_model : backend_context -> model -> string
|
||||
|
||||
val is_model_empty : model -> bool
|
||||
|
||||
val translate_expr :
|
||||
backend_context -> Dcalc.Ast.expr Utils.Pos.marked -> backend_context * vc_encoding
|
||||
end
|
||||
|
||||
module SolverIO (B : Backend) = struct
|
||||
module type SolverIo = sig
|
||||
type vc_encoding
|
||||
|
||||
type backend_context
|
||||
|
||||
type model
|
||||
|
||||
type vc_encoding_result = Success of vc_encoding * backend_context | Fail of string
|
||||
|
||||
val print_positive_result : Conditions.verification_condition -> string
|
||||
|
||||
val print_negative_result :
|
||||
Conditions.verification_condition -> backend_context -> model option -> string
|
||||
|
||||
val encode_and_check_vc :
|
||||
Dcalc.Ast.decl_ctx -> Conditions.verification_condition * vc_encoding_result -> unit
|
||||
end
|
||||
|
||||
module MakeSolverIO (B : Backend) = struct
|
||||
type vc_encoding = B.vc_encoding
|
||||
|
||||
type backend_context = B.backend_context
|
||||
|
||||
type model = B.model
|
||||
|
||||
type vc_encoding_result = Success of B.vc_encoding * B.backend_context | Fail of string
|
||||
|
||||
let print_positive_result (vc : Conditions.verification_condition) : string =
|
||||
|
@ -30,16 +30,31 @@ module type Backend = sig
|
||||
val print_model : backend_context -> model -> string
|
||||
|
||||
val is_model_empty : model -> bool
|
||||
|
||||
val translate_expr :
|
||||
backend_context -> Dcalc.Ast.expr Utils.Pos.marked -> backend_context * vc_encoding
|
||||
end
|
||||
|
||||
module SolverIO : functor (B : Backend) -> sig
|
||||
type vc_encoding_result = Success of B.vc_encoding * B.backend_context | Fail of string
|
||||
module type SolverIo = sig
|
||||
type vc_encoding
|
||||
|
||||
type backend_context
|
||||
|
||||
type model
|
||||
|
||||
type vc_encoding_result = Success of vc_encoding * backend_context | Fail of string
|
||||
|
||||
val print_positive_result : Conditions.verification_condition -> string
|
||||
|
||||
val print_negative_result :
|
||||
Conditions.verification_condition -> B.backend_context -> B.model option -> string
|
||||
Conditions.verification_condition -> backend_context -> model option -> string
|
||||
|
||||
val encode_and_check_vc :
|
||||
Dcalc.Ast.decl_ctx -> Conditions.verification_condition * vc_encoding_result -> unit
|
||||
end
|
||||
|
||||
module MakeSolverIO : functor (B : Backend) ->
|
||||
SolverIo
|
||||
with type vc_encoding = B.vc_encoding
|
||||
and type backend_context = B.backend_context
|
||||
and type model = B.model
|
||||
|
@ -580,6 +580,8 @@ module Backend = struct
|
||||
let print_model (ctx : backend_context) (m : model) : string = print_model ctx m
|
||||
|
||||
let is_model_empty (m : model) : bool = List.length (Z3.Model.get_decls m) = 0
|
||||
|
||||
let translate_expr (ctx : backend_context) (e : Dcalc.Ast.expr Pos.marked) = translate_expr ctx e
|
||||
end
|
||||
|
||||
module Io = Io.SolverIO (Backend)
|
||||
module Io = Io.MakeSolverIO (Backend)
|
||||
|
@ -29,34 +29,14 @@ type context = {
|
||||
|
||||
val translate_expr : context -> Dcalc.Ast.expr Utils.Pos.marked -> context * Z3.Expr.expr
|
||||
|
||||
module Backend : sig
|
||||
type backend_context = context
|
||||
module Backend :
|
||||
Io.Backend
|
||||
with type vc_encoding = Z3.Expr.expr
|
||||
and type backend_context = context
|
||||
and type model = Z3.Model.model
|
||||
|
||||
type vc_encoding = Z3.Expr.expr
|
||||
|
||||
val print_encoding : vc_encoding -> string
|
||||
|
||||
type model = Z3.Model.model
|
||||
|
||||
type solver_result = ProvenTrue | ProvenFalse of model option | Unknown
|
||||
|
||||
val solve_vc_encoding : backend_context -> vc_encoding -> solver_result
|
||||
|
||||
val print_model : backend_context -> model -> string
|
||||
|
||||
val is_model_empty : model -> bool
|
||||
end
|
||||
|
||||
module Io : sig
|
||||
type vc_encoding_result = Io.SolverIO(Backend).vc_encoding_result =
|
||||
| Success of Backend.vc_encoding * Backend.backend_context
|
||||
| Fail of string
|
||||
|
||||
val print_positive_result : Conditions.verification_condition -> string
|
||||
|
||||
val print_negative_result :
|
||||
Conditions.verification_condition -> Backend.backend_context -> Backend.model option -> string
|
||||
|
||||
val encode_and_check_vc :
|
||||
Dcalc.Ast.decl_ctx -> Conditions.verification_condition * vc_encoding_result -> unit
|
||||
end
|
||||
module Io :
|
||||
Io.SolverIo
|
||||
with type vc_encoding = Z3.Expr.expr
|
||||
and type backend_context = context
|
||||
and type model = Z3.Model.model
|
||||
|
Loading…
Reference in New Issue
Block a user