Skip to content

Instantly share code, notes, and snippets.

Created March 21, 2013 22:48
Show Gist options
  • Save anonymous/5217529 to your computer and use it in GitHub Desktop.
Save anonymous/5217529 to your computer and use it in GitHub Desktop.
export Show;
import Numeric;
class Show T {
String show(T);
}
instance Show int {
String show(int x) {
return /* whatever */;
}
}
export Main;
import Numeric, Format;
import IO;
pure T sq[Numeric T](T x) {
return x * x;
}
int main() {
out.print(show(sq(42)));
return 0;
}
export Numeric, int;
infixl `*` 5;
class Numeric T { // type classes!
T `*`(T, T); // * operator
}
type int {
public:
__int value; // __int is primitive
}
instance Numeric int {
int `*`(int a, int b) {
return __imul(a.value, b.value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment