Before we jump fully into monad transformers, let's briefly overview monads.
Intro
Overview of monads
-- functions are defined like so | |
fn add(a: Int, b: Int) -> Int { | |
a + b | |
} | |
-- effects can be declared like so | |
effect fail[E] { | |
fn fail(ctx: E) | |
} |
"Call with current continuation", abbreviated to call/CC or callCC, is an operator popularized by Scheme and often used to implement or emulate nonlocal control transfer in functional languages. However, how call/CC even works is really confusing. It exists at the intersection of higher order functions, continuation passing, and monadic composition; three concepts considered difficult to understand.
Todo: Type signature of callCC, trying to implement callCC, what the b
parameter is for.
Querying one's favorite search engine with the text "a monad is" yields this answer on StackOverflow, which explains, in excruciating mathematical symbology, what a monad in fact is. But, don't worry. Understanding monads doesn't require you to learn the nuances of such concepts as moirails and eigenfunctors. I would suggest that the concept of monads can be distilled into a clearer single sentence.
A monad is a control abstraction that defines a composition of effectful functions.
Let's unpack.
package robosky.uplands.mixin; | |
import java.util.function.Function; | |
import com.mojang.datafixers.kinds.App; | |
import com.mojang.serialization.Codec; | |
import com.mojang.serialization.MapCodec; | |
import com.mojang.serialization.codecs.RecordCodecBuilder; | |
import org.spongepowered.asm.mixin.Dynamic; | |
import org.spongepowered.asm.mixin.Mixin; |
Fabric API is supposed to be modular. This means that mod devs should be able to pick and choose which Fabric API modules to depend on in their mods, both in the development environment and in production.
Fabric API is also supposed to be just another mod. Fabric API should not have special support in Fabric tooling, nor should it be a required install for players. Basically, Fabric API is simply a collection of mostly independent modules that happen to be maintained by the same organization that maintains Fabric tooling.
The fabric example mod contains a hard dependency on the entire Fabric API. Since most mod devs do not remove this dependency, most players have to download an additional mod (Fabric API) in order to play a Fabric mod, which many players do not expect. This means mod devs often assume that players have installed Fabric API in the production evnironment.
package access; | |
public class AccessTest { | |
public static void main(String[] args) { | |
UseM.use(new q.Sub()); // prints "Subclass" | |
// new q.Sub().m(); // compiler error - cannot access protected method m | |
((p.Super)new q.Sub()).m(); // prints "Subclass" | |
} | |
} |
/*********************************************************************************************************************************************************************************************************************/ | |
/* SpongePowered MIXIN */ | |
/*********************************************************************************************************************************************************************************************************************/ | |
/* Code source : file:/home/.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.7.11.36/b0d9944f2b77f1ce952a1179e595037332910a82/sponge-mixin-0.7.11.36.jar */ | |
/* Internal Version : 0.7.11 |
---- Minecraft Crash Report ---- | |
// Why is it breaking :( | |
Time: 5/10/19, 10:55 PM | |
Description: Exception generating new chunk | |
java.util.ConcurrentModificationException | |
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134) | |
at net.minecraft.structure.StructureManager.getStructure(StructureManager.java:58) | |
at net.minecraft.structure.StructureManager.getStructureOrBlank(StructureManager.java:47) |