Skip to content

Instantly share code, notes, and snippets.

@be5invis
Last active December 31, 2015 18:29
Show Gist options
  • Save be5invis/8027415 to your computer and use it in GitHub Desktop.
Save be5invis/8027415 to your computer and use it in GitHub Desktop.
Conceptional language + type system
// 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