Skip to content

Instantly share code, notes, and snippets.

@makoConstruct
Last active August 29, 2015 14:18
Show Gist options
  • Save makoConstruct/d5c38371ff95acfe794f to your computer and use it in GitHub Desktop.
Save makoConstruct/d5c38371ff95acfe794f to your computer and use it in GitHub Desktop.
Application of dependent types
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