From 2d5c3288134f19088941c980e852521e9838db56 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Sat, 24 Sep 2022 12:35:20 -0400 Subject: Various changes --- src/main/java/bjc/funcdata/CList.java | 54 ++++++++++++++++++++++ src/main/java/bjc/funcdata/CListLike.java | 13 ++++++ src/main/java/bjc/funcdata/CListStructure.java | 38 +++++++++++++++ .../bjc/funcdata/bst/TreeLinearizationMethod.java | 2 +- src/main/java/bjc/funcdata/theory/Category.java | 28 +++++++++++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 src/main/java/bjc/funcdata/CList.java create mode 100644 src/main/java/bjc/funcdata/CListLike.java create mode 100644 src/main/java/bjc/funcdata/CListStructure.java create mode 100644 src/main/java/bjc/funcdata/theory/Category.java (limited to 'src/main/java/bjc/funcdata') 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 implements CListLike { + private Either>> data; + + private CList() { + data = Either.left(Unit.UNIT); + } + + private CList(T data, CList 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 tail() { + return data.forceRight().getRight(); + } + + @Override + public CList prefix(T val) { + return new CList<>(val, this); + } + + public static UnaryOperator> prefixing(T val) { + return (lst) -> lst.prefix(val); + } + + public static CList empty() { + return new CList<>(); + } + public static CList of(T... vals) { + CList 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 { + + boolean isEmpty(); + + T head(); + + CListLike tail(); + + CListLike 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 implements CListLike>> { + private Either>> data; + + public boolean isAtomic() { + return data.isLeft(); + } + + @Override + public boolean isEmpty() { + return true; + } + + @Override + public Either> head() { + if (isAtomic()) return data.newRight(); + // ... Beats me + return null; + } + + @Override + public CListLike>> tail() { + // TODO Auto-generated method stub + return null; + } + + @Override + public CListLike>> prefix(Either> 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 { + Arrow identity(Element elem); + Arrow compose(Arrow left, Arrow right); +} +// Java objects would form a category as Category, Function> + +class FuncCategory implements Category, Function> { + @Override + public Function identity(Class elem) { + return (vl) -> vl; + } + + @Override + public Function compose(Function left, Function right) { + // right.compose((Function) left); + return null; + } + +} \ No newline at end of file -- cgit v1.2.3