I would like to understand how Frege List works and how is it possible to use it from Java. While I downloaded the Frege compiler code, I found difficult to understand what a Frege List is from the Frege code.
Doing some tests I saw that a Frege List is an instance of the TList
class in Java with a special method, called _Cons()
, that returns a DCons
object. DCons
is, as expected, a pair where the first element of the pair corresponds to the head of the list while the second element is the tail, thus another TList
. When _Cons()
is called on an empty lists, the return value is null. Therefore, to implement a Java iterator over Frege TList
, one could write:
public class TListIterator implements Iterator<Object> {
DCons elem;
public TListIterator(TList list) {
this.elem = list._Cons();
}
@Override
public boolean hasNext() {
return this.elem != null;
}
@Override
public Object next() {
final Object head = Delayed.<Object>forced( this.elem.mem1 );
this.elem = this.elem.mem2.<TList>forced()._Cons();
return head;
}
@Override
public void remove() {
throw new RuntimeException( "Remove is not implemented" );
}
}
My questions are:
- Is my explanation of
TList
correct? - Is
TListIterator
correct? - where can I find more informations on what
TList
,DList
andDCons
are in the Frege compiler source code? Are they documented? - A more generic question on best practices in Frege: when you want Java code to use a Frege value, is it better to return Java "standard" Objects from Frege code or is it better to directly use Frege classes from Java? My opinion is that the former is easier to write than the latter but has a little conversion overhead. For instance, a
TListIterator
can always be avoided by converting theTList
into a JavaLinkedList
from Frege.