Skip to content

Instantly share code, notes, and snippets.

f :: x <: Int+[String] -> {
case x of
Int = x
[String] = length x
| x <- x
}
data SomeData a b = A a | B b
get :: s <: SomeData a b -> {
case dat of
A a = a
B b = b
| dat <- s
}
x :: Int = get (A 3)
length :: l <: [a] -> { -- This is just a type comprehension spanned over lines, with a full language of syntax
case xxs of
x:xs = 1 + length xs
[] = 0
| xxs <- l
}
data Something a b c = A a | B b | C c
func :: s <: Something a b c - {C _} => s -> Either a b
func s = case s of
A(a) = Left a
B(b) = Right b
div :: ia <: Int, ib <: Int - {0} => ia -> ib -> { a / b | a <- ia, b <- ib }
div a b = a / b
div :: n = { i <- Int | i != 0} => Int -> n -> Int
-- or more simply, using set subtraction
div :: n = Int - {0} => Int -> n -> Int
div a b = a / b
div :: Int -> Int -> Int
div a b = a / b
@ElvishJerricco
ElvishJerricco / StoragePart.java
Created July 18, 2015 03:57
Create peripheral
public class StoragePart extends PartBase<PartFactoryPeripherals> implements IWorldNetworkNodeHost, TSlottedPart {
...
private SinglePeripheralModem modem = new SinglePeripheralModem() {
private final PeripheralOfEnumMethods<StoragePart, ExampleMethods> peripheral =
new PeripheralOfEnumMethods<StoragePart, ExampleMethods>(
StoragePart.this,
ExampleMethods.class,
"exampe_peripheral"
@ElvishJerricco
ElvishJerricco / ExampleMethods.java
Created July 17, 2015 21:47
example peripheral methods
public enum ExampleMethods implements IEnumPeripheralMethods<StoragePart> {
GetPosition("getPosition") {
@Override
public Object[] call(StoragePart data, IComputerAccess iComputerAccess, ILuaContext iLuaContext, Object[] objects)
throws LuaException, InterruptedException {
return new Object[] {data.x(), data.y(), data.z()};
}
},
GetDirection("getDirection") {
@Override
@ElvishJerricco
ElvishJerricco / IEnumPeripheralMethods.java
Created July 17, 2015 21:39
Enum peripheral methods
public interface IEnumPeripheralMethods<T> {
String getMethodName();
Object[] call(T data, IComputerAccess iComputerAccess, ILuaContext iLuaContext, Object[] objects) throws LuaException, InterruptedException;
}