Created
March 21, 2013 22:48
-
-
Save anonymous/5217529 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
export Show; | |
import Numeric; | |
class Show T { | |
String show(T); | |
} | |
instance Show int { | |
String show(int x) { | |
return /* whatever */; | |
} | |
} |
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
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; | |
} | |
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
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