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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:46:31+00:00 2026-05-30T14:46:31+00:00

I want to crate a tuple, that holds an arrow and a string that

  • 0

I want to crate a tuple, that holds an arrow and a string that describes the arrow. If i do so with functions (instead of arrows), the following works like expected:

funTimes10 = (*10)
describe10 = "times 10"

tuple10 :: (Num b) => ((b -> b), String)
tuple10 = (,) funTimes10 describe10

I can access the function with fst, and with snd i get the description string of the function.

However, if i exchange the function with an arrow, like in the following:

aTuple10 :: (Arrow a, Num b) => (a b b, String)
aTuple10 = (,) (arr funTimes10) describe10
  • fst still works and returns my arrow, but
  • i don’t get any description string with snd.

I only got this error-message:

Ambiguous type variable `a0' in the constraint:
  (Arrow a0) arising from a use of `aTuple10'
Probable fix: add a type signature that fixes these type variable(s)
In the first argument of `snd', namely `aTuple10'
In the expression: (snd aTuple10)
In an equation for `it': it = (snd aTuple10)

Why do i get this error, and what should i do, to avoid it?

  • 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-30T14:46:32+00:00Added an answer on May 30, 2026 at 2:46 pm

    Let’s look at the type of snd:

    snd :: (foo, x) -> x
    

    (I renamed the type variables for clarity)

    What the type states is that for a tuple with types foo and x, return something of type x. Something important to know here is that while the value system aka. runtime in Haskell is lazy, Haskell’s type system is strict, meaning that both the types of foo and x must be known before snd can be called.

    In the first case, when you just have a Num b => (b -> b, String), calling snd will leave b ambiguous, because you don’t mention its concrete type anywhere, and it can’t be inferred from the return type because foo ~ b which is distinct from x. In other words: because (b, b) can be a tuple of any number type, and the type checker can’t figure out which one, it is ambiguous. The trick here is that we’ll have Haskell’s defaulting rules kick in, which state that if a numeric type is ambiguous, it should default to Integer. If you had turned warnings on with -Wall, it would have said that this is happening. So, our type becomes (Integer -> Integer, String) and snd can be called.

    In the second case, however, we still manage to infer b via the defaulting rules, but there is no default Arrow for a, so we’re stuck! You must explicitly specify which arrow you want in order to continue! You can either do this by first using a value of aTuple10 somewhere else:

    let bla = aTuple10  -- We do this because `aTuple10` can have type variables, but `bla` cannot (by default)
    fst bla (23 :: Int) -- This fixes the type of `bla`, so that `a ~ (->)` and `b ~ Int`
    print $ snd bla     -- So the arrow isn't ambiguous here
    

    … or you can just specify the type that you want:

    print $ snd (aTuple10 :: (Int -> Int, String))
    

    PS if you want to change the default type of ambiguous numbers, the default keyword can help you out.

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

Sidebar

Related Questions

I want to crate custom TableLayout with rows like this: TV is for TextView,
I want to use % -style string formatting to print a tuple: tup =
I have a 3-tuple data set (X,Y,Z points) that I want to plot using
I have a situation where I want to create a mapping from a tuple
I want to create a function that performs a function passed by parameter on
I want to create a simple http proxy server that does some very basic
I want to create an allocator which provides memory with the following attributes: cannot
I have implemented some version of tuple class , and really want to learn
I'm trying to find an alternative to List<Tuple<Grid, TabItem, int, string, int>>... , since
In the following code, I would like to insert or update rows in an

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.