You are indeed right. However, this is my first real try at ATS (not
counting toy
problems) and, so, I wanted to have something that works and then start
polishing it.
About the way keep is called, I have essentially tried two similar methods.
However, before giving those two methods, I should first give the following
type
definitions:
typedef RelationalInterpretation_AD(domain_size:int, arity:int) = List0(@[
NatLt(domain_size)][arity])
typedef RelationalInterpretation_D(domain_size:int) = [arity:nat]
RelationalInterpretation_AD(domain_size, arity)
typedef RelationalInterpretation_A(arity:int) = [domain_size:pos]
RelationalInterpretation_AD(domain_size, arity)
typedef RelationalInterpretation = [domain_size:pos] [arity:nat]
RelationalInterpretation_AD(domain_size, arity)
Essentially, these types say that the interpretation of a relational symbol
is a list of
tuples so that each tuple is represented by an array of size “arity” and
the numbers inside
each position of the tuple ranges from 0 to n-1 where “n” is the size of
the domain. The
postfix of the names above show which one of the two type parameters
(arity/domain size)
are present. Now, the two methods that I have tried:
The first method is as follows:
implement list_filter$pred<@[Nat][arity]> (x) = keep(x, cv)
In this method, I call “list_filter(i)” with “i” being of type
RelationalInterpretation_A(arity)
The second method is essentially an implementation of filter function as
below:
fun loop {arity:nat} {domain_size:pos} (
i:RelationalInterpretation_AD(domain_size, arity),
cur_res:RelationalInterpretation_AD(domain_size, arity)) :
RelationalInterpretation_AD(domain_size, arity) =
case+ i of
| list_nil() => cur_res
| list_cons(row, rest) =>
if (keep(row, cv)) then
loop(rest, list_cons(row, cur_res))
else
loop(rest, cur_res)
In this method, I call “loop(i, list_nil())” with “i” being the same type
as before.
Again, I know that it is not the cleanest code I could have written but, as
a person new to
ATS, I prefer to start with something that uses basic programming
constructs in ATS and
learn about the more advanced programming style as I go forward.