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 8039871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:43:05+00:00 2026-06-05T03:43:05+00:00

Is there any type-safe way to write a function bi f a b =

  • 0

Is there any type-safe way to write a function

bi f a b = (f a, f b)

such that it would be possible to use it like this:

x1 :: (Integer, Char)
x1 = bi head [2,3] "45"

x2 :: (Integer, Char)
x2 = bi fst (2,'3') ('4',5)

x3 :: (Integer, Double)
x3 = bi (1+) 2 3.45

?
In rank-n-types examples there are always something much simpler like

g :: (forall a. a -> a) -> a -> a -> (a, a)
g f a b = (f a, f b)
  • 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-06-05T03:43:07+00:00Added an answer on June 5, 2026 at 3:43 am

    Yes, though not in Haskell. But the higher-order polymorphic lambda calculus (aka System F-omega) is more general:

    bi : forall m n a b. (forall a. m a -> n a) -> m a -> m b -> (n a, n b)
    bi {m} {n} {a} {b} f x y = (f {a} x, f {b} y)
    
    x1 : (Integer, Char)
    x1 = bi {\a. List a} {\a. a} {Integer} {Char} head [2,3] "45"
    
    x2 : (Integer, Char)
    x2 = bi {\a . exists b. (a, b)} {\a. a} {Integer} {Char} (\{a}. \p. unpack<b,x>=p in fst {a} {b} x) (pack<Char, (2,'3')>) (pack<Integer, ('4',5)>)
    
    x3 : (Integer, Double)
    x3 = bi {\a. a} {\a. a} {Integer} {Double} (1+) 2 3.45
    

    Here, I write f {T} for explicit type application and assume a library typed respectively. Something like \a. a is a type-level lambda. The x2 example is more intricate, because it also needs existential types to locally “forget” the other bit of polymorphism in the arguments.

    You can actually simulate this in Haskell by defining a newtype or datatype for every different m or n you instantiate with, and pass appropriately wrapped functions f that add and remove constructors accordingly. But obviously, that’s no fun at all.

    Edit: I should point out that this still isn’t a fully general solution. For example, I can’t see how you could type

    swap (x,y) = (y,x)
    x4 = bi swap (3, "hi") (True, 3.1)
    

    even in System F-omega. The problem is that the swap function is more polymorphic than bi allows, and unlike with x2, the other polymorphic dimension is not forgotten in the result, so the existential trick does not work. It seems that you would need kind polymorphism to allow that one (so that the argument to bi can be polymorphic over a varying number of types).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way that I can detect browser type on routing and use
Is there any primitive data type that it's safe to not initialize? How about
Is there any proper way to make TH's functions safe if they use side
Are there any standalone type conversion libraries? I have a data storage system that
Is there any convenient way to type in braces in Math in Latex? Especially
Is there any way to find the exact file type in php without looking
Is there any way to specify what specific type of object can be contained
Is there any way to store the generic parameter type passed in at construction
i have this issue working but i would like to know if there is
Is any practical way to reference a method on a class in a type-safe

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.