I think this is a question of dispassion. The standard library provides unmanaged functions for products, see uncurry . It would be more beneficial for your situation to have a non-alienation function where the first argument is hidden, since the head function usually takes a length index as an implicit argument. We can write a fatal function such as:
uncurryΚ° : β {abc} {A : Set a} {B : A β Set b} {C : (a : A) β B a β Set c} β ({x : A} β (y : B x) β C xy) β ((p : Ξ£ AB) β uncurry C p) uncurryΚ° f (x , y) = f {x} y
The function that returns the head of the vector, if there is one, does not seem to exist in the standard library, so we write one:
maybe-head : β {an} {A : Set a} β Vec A n β Maybe A maybe-head [] = nothing maybe-head (x β· xs) = just x
Now your desired function is just a possibly-head question with the first-argument-implicit-unmanaged function defined above:
maybe-filter-head : β {A : Set} {n} β (A β Bool) β Vec A n β Maybe A maybe-filter-head p = uncurryΚ° maybe-head β filter p
Conclusion: dependent products look happy and ugly, as do their independent versions.
Leaving aside, the function you want to write with a signature like
head : β {A} β β (Ξ» n β Vec A n) β IsTrue (n β₯ succ zero) β A
It can be written as:
head : β {A} β (p : β (Ξ» n β Vec A n)) β IsTrue (projβ p β₯ succ zero) β A
source share