Created
June 2, 2023 08:36
-
-
Save steshaw/7e85bcc2783081159b455f33257efb88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/namin/unsound/blob/master/Unsound9.java | |
class Unsound9<U,T> { | |
static class Type<A> { | |
class Constraint<B extends A> extends Type<B> {} | |
<B> Constraint<? super B> bad() { return null; } | |
<B> A coerce(B b) { | |
return pair(this.<B>bad(), b).value; | |
} | |
} | |
static class DependentSum<T> { | |
Type<T> type; | |
T value; | |
DependentSum(Type<T> t, T v) { | |
type = t; | |
value = v; | |
} | |
} | |
static <T> DependentSum<T> pair(Type<T> type, T value) { | |
return new DependentSum<T>(type, value); | |
} | |
static <T,U> U coerce(T t) { | |
Type<U> type = new Type<U>(); | |
return type.<T>coerce(t); | |
} | |
public static void main(String[] args) { | |
String zero = Unsound9.<Integer,String>coerce(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment