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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:59:18+00:00 2026-05-27T12:59:18+00:00

When using the interactive GHC interpreter, it’s possible to ask for the inferred type

  • 0

When using the interactive GHC interpreter, it’s possible to ask for the inferred type of an expression:

Prelude> :t map
map :: (a -> b) -> [a] -> [b]

It seems that it takes the names of the type variables from the signature since map is defined as

map :: (a -> b) -> [a] -> [b]
map _ []     = []
map f (x:xs) = f x : map f xs

in the Prelude. That makes a lot of sense! My question is: how are type variable names picked when there is no signature given?

An example would be

Prelude> :t map fst
map fst :: [(b, b1)] -> [b]

where it picked names b and b1. It’s clear that renaming must take place, but simply starting with a, b, … would have given

map fst :: [(a, b)] -> [a]

instead, which I find slightly more readable.

  • 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-27T12:59:18+00:00Added an answer on May 27, 2026 at 12:59 pm

    As I understand it, ghci chooses names in the same order that it infers the types. It uses the naming scheme as you mentioned to decide the type name of the result, which is [b] because that is the type name specified in the definition of map. It then decides that the function that is the first parameter to map should return something of type b also.

    The remaining type variable to be named is thus the type variable for the second element in the argument tuple to fst, and again, it looks at the definition of fst to decide which name to use. The definition of fst :: (a, b) -> a, so b would be the preferred name here, but since b is already taken, it appends a 1 so that it becomes b1.

    I think that this system has advantages in situations where you don’t deal with arbitrary types as is the case here. If the resulting type looks something like this, for example:

    castAdd :: (Num n, Num n1, Num n2) => n -> n1 -> n2
    

    … it is arguably more readable than:

    castAdd :: (Num a, Num b, Num c) => a -> b -> c
    

    … because you can mostly rely on that n# signifies a numeric type, since the class definition for Num is class Num n where ....

    EDIT: Yes, I know that castAdd is impossible to implement, but it’s just a type example.

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

Sidebar

Related Questions

I know that it's possible to implicitly provide asynchronous interaction using: Asynchronous Delegates Asynchronous
Possible Duplicate: How do you express binary literals in Python? When using the interactive
I want to create an interactive website using aspx and ajax, that there will
I am trying to build an interactive map using an imagemap and jquery. I
I'm using the jQuery plugin that generates interactive tables called jqGrid . I want
Currently am using an interactive flash map on my website, which displays different colors
I'm having some trouble using SML/NJ interactive system, namely, that when I try to
I'm observing some strange behavior when using the F# interactive interpreter. Running the following
I'm used to ending the python interactive interpreter using Ctrl-d using Linux and OS
I'm using google maps' Interactive Polyline Encoder Utility to plot locations on a map.

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.