Last active
August 29, 2015 14:18
-
-
Save makoConstruct/d5c38371ff95acfe794f to your computer and use it in GitHub Desktop.
Application of dependent types
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
class SizedArray[V, length:Int] | |
def zipmap[T, otherLength:Int](f:(V, V)=>T, other:SizedArray[otherLength,T]):SizedArray[math.min(length, otherLength),T] = | |
const val minLength = math.min(length, otherLength) | |
retval = new SizedArray[V,minLength] | |
for i in range(0, minLength) | |
retval(i) = f(this(i), other(i)) | |
return retval | |
class Array[V] | |
def zipmap[T](f:(V, V)=>T, other:Array[T]):Array[T] = | |
val minLength = math.min(this.length, other.length) | |
retval = new Array[V](minLength) | |
for i in range(0, minLength) | |
retval(i) = f(this(i), other(i)) | |
return retval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment