-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerms.cs
32 lines (27 loc) · 1005 Bytes
/
Terms.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace biscuit_net.Datalog;
public abstract record Term
{
public abstract Term Apply(Substitution env);
public static implicit operator Term(string s) =>
s.StartsWith('$')
? new Variable(s.TrimStart('$'))
: new Symbol(s);
public static implicit operator Term(bool b) => new Boolean(b);
public static implicit operator Term(long b) => new Integer(b);
public static implicit operator Term(byte[] b) => new Bytes(b);
public static implicit operator Term(DateTime d) => new Date(Date.ToTAI64(d));
}
public sealed record Variable(string Name) : Term
{
public override Term Apply(Substitution env) => env.GetValueOrDefault(this, this);
public override string ToString() => $"<{Name}>";
}
public sealed record Symbol(string Name) : Term
{
public override Term Apply(Substitution env) => this;
public override string ToString() => Name;
}
public record Constant : Term
{
public override Term Apply(Substitution env) => this;
}