Reason for filter's result being alias-free, but partition's result not?
#2328
-
|
I find Futhark's type system fascinating, and while playing around, I noticed that filter : [n] 'a (a -> bool) ([n]a): *[]a
partition : [n] 'a (a -> bool) ([n]a): ?[k].([k]a, [n-k]a)I didn't quite understand why that is, given that in-place partitioning is a bit like in-place filtering without the final length truncation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
I don't think we thought carefully about it, but the reason is that This can be changed in two ways:
|
Beta Was this translation helpful? Give feedback.
I don't think we thought carefully about it, but the reason is that
partitionends by taking two slices of the same array and then returning them - that means they are aliased (as far as Futhark is concerned), although we of course know that they will not truly be aliased.This can be changed in two ways:
copyat the end offilter, although the caller might as well do that.splitthat understands that the two arrays cannot alias.