Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions languages/j/java/LambdaCore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import java.util.function.Function;

public interface LambdaCore {

interface Bool extends Function<Bool, Function<Bool, Bool>> {
}

interface UnaryBoolOp extends Function<Bool, Bool> {
}

interface BinaryBoolOp extends Function<Bool, Function<Bool, Bool>> {
}

interface ChurchNumeral extends Function<Function<Integer, Integer>, Function<Integer, Integer>> {
}

Bool TRUE = x -> y -> x;
Bool FALSE = x -> y -> y;

UnaryBoolOp NOT = b -> b.apply(FALSE).apply(TRUE);
BinaryBoolOp AND = b1 -> b2 -> b1.apply(b2).apply(FALSE);
BinaryBoolOp OR = b1 -> b2 -> b1.apply(TRUE).apply(b2);

ChurchNumeral ZERO = x -> y -> y;
Function<ChurchNumeral, ChurchNumeral> SUCC = w -> y -> x -> y.apply(w.apply(y).apply(x));

// Function<ChurchNumeral, ChurchNumeral> PRED = n -> f -> x ->
// n.apply(g -> h -> h.apply(g.apply(f)))
// .apply(u -> x)
// .apply(u -> u);

static void main(String[] args) {
printBool(TRUE); // TRUE
printBool(FALSE); // FALSE

printBool(NOT.apply(TRUE)); // FALSE
printBool(NOT.apply(FALSE)); // TRUE

printBool(AND.apply(FALSE).apply(FALSE)); // FALSE
printBool(AND.apply(TRUE).apply(FALSE)); // FALSE
printBool(AND.apply(FALSE).apply(TRUE)); // FALSE
printBool(AND.apply(TRUE).apply(TRUE)); // TRUE

printBool(OR.apply(FALSE).apply(FALSE)); // FALSE
printBool(OR.apply(TRUE).apply(FALSE)); // TRUE
printBool(OR.apply(FALSE).apply(TRUE)); // TRUE
printBool(OR.apply(TRUE).apply(TRUE)); // TRUE

printChurchNumeral(ZERO); // 0
printChurchNumeral(SUCC.apply(ZERO)); // 1
}

static void printBool(Bool b) {
if (b == TRUE)
System.out.println("BOOLEAN TRUE");
else if (b == FALSE)
System.out.println("BOOLEAN FALSE");
else
throw new IllegalStateException();
}

static void printChurchNumeral(ChurchNumeral n) {
System.out.println(n.apply(x -> x + 1).apply(0));
}
}
23 changes: 23 additions & 0 deletions languages/j/java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Java 21 Installation Guide

## Download Java 21
Download Java 21 from the official Oracle website:
[Java 21 Downloads](https://www.oracle.com/in/java/technologies/downloads/#java21)

## Installation Steps
1. Select the appropriate JDK version for your OS (Windows, macOS, or Linux).
2. Download the installer or compressed archive.
3. Follow the installation instructions provided by Oracle.

## Verify Installation
Run the following command to check the installed Java version:

```sh
java -version
```

# Run Code

```sh
java LambdaCore.java
```