summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/funcdata
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/bjc/funcdata')
-rw-r--r--src/main/java/bjc/funcdata/CList.java54
-rw-r--r--src/main/java/bjc/funcdata/CListLike.java13
-rw-r--r--src/main/java/bjc/funcdata/CListStructure.java38
-rw-r--r--src/main/java/bjc/funcdata/bst/TreeLinearizationMethod.java2
-rw-r--r--src/main/java/bjc/funcdata/theory/Category.java28
5 files changed, 134 insertions, 1 deletions
diff --git a/src/main/java/bjc/funcdata/CList.java b/src/main/java/bjc/funcdata/CList.java
new file mode 100644
index 0000000..b9ee10e
--- /dev/null
+++ b/src/main/java/bjc/funcdata/CList.java
@@ -0,0 +1,54 @@
+package bjc.funcdata;
+
+import java.util.function.UnaryOperator;
+
+import bjc.data.Either;
+import bjc.data.Pair;
+import bjc.functypes.Unit;
+
+public class CList<T> implements CListLike<T> {
+ private Either<Unit, Pair<T, CList<T>>> data;
+
+ private CList() {
+ data = Either.left(Unit.UNIT);
+ }
+
+ private CList(T data, CList<T> rest) {
+ this.data = Either.right(Pair.pair(data, rest));
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return data.isLeft();
+ }
+
+ @Override
+ public T head() {
+ return data.forceRight().getLeft();
+ }
+
+ @Override
+ public CList<T> tail() {
+ return data.forceRight().getRight();
+ }
+
+ @Override
+ public CList<T> prefix(T val) {
+ return new CList<>(val, this);
+ }
+
+ public static <T> UnaryOperator<CList<T>> prefixing(T val) {
+ return (lst) -> lst.prefix(val);
+ }
+
+ public static <T> CList<T> empty() {
+ return new CList<>();
+ }
+ public static <T> CList<T> of(T... vals) {
+ CList<T> ret = empty();
+ for (int i = vals.length - 1; i >= 0; i-- ) {
+ ret = ret.prefix(vals[i]);
+ }
+ return ret;
+ }
+}
diff --git a/src/main/java/bjc/funcdata/CListLike.java b/src/main/java/bjc/funcdata/CListLike.java
new file mode 100644
index 0000000..ba17456
--- /dev/null
+++ b/src/main/java/bjc/funcdata/CListLike.java
@@ -0,0 +1,13 @@
+package bjc.funcdata;
+
+public interface CListLike<T> {
+
+ boolean isEmpty();
+
+ T head();
+
+ CListLike<T> tail();
+
+ CListLike<T> prefix(T val);
+
+} \ No newline at end of file
diff --git a/src/main/java/bjc/funcdata/CListStructure.java b/src/main/java/bjc/funcdata/CListStructure.java
new file mode 100644
index 0000000..1809273
--- /dev/null
+++ b/src/main/java/bjc/funcdata/CListStructure.java
@@ -0,0 +1,38 @@
+package bjc.funcdata;
+
+import bjc.data.Either;
+
+// pretty sure we want to implement CListLike, but not obvious how to implement
+public class CListStructure<T> implements CListLike<Either<T, CListLike<T>>> {
+ private Either<T, CList<CListStructure<T>>> data;
+
+ public boolean isAtomic() {
+ return data.isLeft();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return true;
+ }
+
+ @Override
+ public Either<T, CListLike<T>> head() {
+ if (isAtomic()) return data.newRight();
+ // ... Beats me
+ return null;
+ }
+
+ @Override
+ public CListLike<Either<T, CListLike<T>>> tail() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public CListLike<Either<T, CListLike<T>>> prefix(Either<T, CListLike<T>> val) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ // There are almost certainly other methods we want here, just not sure what
+}
diff --git a/src/main/java/bjc/funcdata/bst/TreeLinearizationMethod.java b/src/main/java/bjc/funcdata/bst/TreeLinearizationMethod.java
index 65c013b..666834f 100644
--- a/src/main/java/bjc/funcdata/bst/TreeLinearizationMethod.java
+++ b/src/main/java/bjc/funcdata/bst/TreeLinearizationMethod.java
@@ -17,7 +17,7 @@ public enum TreeLinearizationMethod {
*/
POSTORDER,
/**
- * Visit the tree part itself, then the left side of tthis tree part and then
+ * Visit the tree part itself, then the left side of this tree part and then
* the right part.
*/
PREORDER
diff --git a/src/main/java/bjc/funcdata/theory/Category.java b/src/main/java/bjc/funcdata/theory/Category.java
new file mode 100644
index 0000000..730465d
--- /dev/null
+++ b/src/main/java/bjc/funcdata/theory/Category.java
@@ -0,0 +1,28 @@
+package bjc.funcdata.theory;
+
+import java.util.Set;
+import java.util.function.Function;
+
+import bjc.data.Pair;
+import bjc.esodata.PairMap;
+
+// NOTE: haskell uses Category cat: ... where the parameter is the arrow type
+public interface Category<Element, Arrow> {
+ Arrow identity(Element elem);
+ Arrow compose(Arrow left, Arrow right);
+}
+// Java objects would form a category as Category<Class<?>, Function<?, ?>>
+
+class FuncCategory implements Category<Class<?>, Function<?, ?>> {
+ @Override
+ public Function<?, ?> identity(Class<?> elem) {
+ return (vl) -> vl;
+ }
+
+ @Override
+ public Function<?, ?> compose(Function<?, ?> left, Function<?, ?> right) {
+ // right.compose((Function<? super V, ?>) left);
+ return null;
+ }
+
+} \ No newline at end of file