1use std::hash::Hash;
2
3pub trait TermContext {
4 type Term: Term;
5 type NoArgError: std::error::Error;
6
7 fn term_from_arg(
8 &self,
9 arg: <Self::Term as Term>::Arg<'_>,
10 ) -> Result<&Self::Term, Self::NoArgError>;
11}
12
13pub trait Term {
14 type Context: TermContext;
15 type Operation: Eq + Hash;
16 type Arg<'a>: Copy
17 where Self: 'a;
18
19 fn arity(&self) -> usize;
20
21 fn arg(&self, idx: usize) -> Option<Self::Arg<'_>>;
22}
23
24pub trait TermArg<'a, C: TermContext>: Sized
25where C::Term: Term<Arg<'a> = Self> + 'a
26{
27 fn term(self, ctx: &C) -> Result<&C::Term, C::NoArgError> { ctx.term_from_arg(self) }
28}