Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7627981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:32:01+00:00 2026-05-31T05:32:01+00:00

Suppose I have a function (it really does what the name says): filter :

  • 0

Suppose I have a function (it really does what the name says):

filter : ∀ {A n} → (A → Bool) → Vec A n → ∃ (λ m → Vec A m)

Now, I’d like to somehow work with the dependent pair I return. I wrote simple head function:

head :: ∀ {A} → ∃ (λ n → Vec A n) → Maybe A
head (zero   , _ )       = nothing
head (succ _ , (x :: _)) = just x

which of course works perfectly. But it made me wonder: is there any way I can make sure, that the function may only be called with n ≥ 1?

Ideally, I’d like to make function head : ∀ {A} → ∃ (λ n → Vec A n) → IsTrue (n ≥ succ zero) → A; but that fails, because n is out of scope when I use it in IsTrue.

Thanks for your time!


IsTrue is something like:

data IsTrue : Bool → Set where
  check : IsTrue true
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:32:02+00:00Added an answer on May 31, 2026 at 5:32 am

    I think this is a question about uncurrying. The standard library provides uncurrying
    functions for products, see uncurry.
    For your situation, it would be more beneficial to have a uncurry function where the first
    argument is hidden, since a head function would normally take the length index as an implicit argument.
    We can write an uncurry function like that:

    uncurryʰ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : (a : A) → B a → Set c} →
               ({x : A} → (y : B x) → C x y) →
               ((p : Σ A B) → uncurry C p)
    uncurryʰ f (x , y) = f {x} y
    

    The function that returns the head of a vector if there is one does not seem to exist in the standard library,
    so we write one:

    maybe-head : ∀ {a n} {A : Set a} → Vec A n → Maybe A
    maybe-head []       = nothing
    maybe-head (x ∷ xs) = just x
    

    Now your desired function is just a matter of uncurrying the
    maybe-head function with the first-argument-implicit-uncurrying
    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 gladly curry and uncurry like their non-dependent versions.

    Uncurrying aside, the function you want to write with type signature

    head : ∀ {A} → ∃ (λ n → Vec A n) → IsTrue (n ≥ succ zero) → A
    

    Can be written as:

    head : ∀ {A} → (p : ∃ (λ n → Vec A n)) → IsTrue (proj₁ p ≥ succ zero) → A
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a function which looks like this: template <class In, class In2>
Suppose I have a free function called InitFoo . I'd like to protect this
Suppose I have simple class like: class MyClass { private $_prop; public function getProp()
Let's suppose I have a C extension function that does something that is completely
Suppose I have virtual function foo() in class B, and I need slightly different
Suppose I have this function: void my_test() { A a1 = A_factory_func(); A a2(A_factory_func());
Suppose I have a function: function my_function($a, $b, $c) { ... } I want
Suppose I have a function which can either take an iterable/iterator or a non-iterable
Suppose I have a C function: void myFunction(..., int nObs){ int myVec[nObs] ; ...
Suppose you have the following function foo . When I'm running a for loop,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.