Last active
December 31, 2015 18:29
-
-
Save be5invis/8027415 to your computer and use it in GitHub Desktop.
Conceptional language + type system
This file contains hidden or 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
// data types | |
type[T] Point { | |
data x : T | |
data y : T | |
} | |
type IntPoint = Point[Integer] | |
// complex concepts | |
type[T <= Differable] DifferenceOf { | |
to +(b : T) : T | |
} | |
type Differable { | |
to -(b : T) : DifferenceOf[T] | |
to +(b : DifferenceOf[T]) : T | |
} | |
type Time { implements Diffeerable } | |
type TimeSpan = DifferenceOf[Time] | |
// conversion concept | |
type[Q] CanConvertTo { | |
to convert : Q | |
} | |
type[Q] CanLosslesslyConvertTo { | |
to losslesslyConvert : Q | |
implements CanConvertTo[Q] { | |
to convert = (this as CanLosslesslyConvertTo[Q]) :: losslesslyConvert | |
} | |
} | |
type Integer { | |
implements CanLosslesslyConvertTo[String] { | |
to losslesslyConvert = LIBRARY_CONVERT_INT_TO_STRING(this) | |
} | |
} | |
function[P <= CanConvertTo[Q], Q] convert(x : P) : Q { | |
return x.convert | |
// longhand: return (x as CanConvertTo[Q]).convert | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment