Super types are the types of claasses. they are like static interfaces/traits. they establish a contract with the class, not with the instance
public type class AdditionMonoid<T>
given T is AdditionMonoid<T>
{
public plus (a :T, b:T) : T;
public zero():T
}
public interface Integer satisfies AdditionMonoid<Integer> {
public satisfy zero() => 0;
public satisfy plus (a,b) => a.plus(b);
public plus (a: Integer) : Integer;
}
// define based on type
public enhancement SumSequence extends Sequence<T> given T is AdditionMonoid<T>{
public sum() {
return this.reduce(T.zero(), (x,y) => T.plus(x,y));
}
}
//use
assert (21, [1,2,3,4,5,6].sum());
Super types are the types of claasses. they are like static interfaces/traits. they establish a contract with the class, not with the instance