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

  • Home
  • SEARCH
  • 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 6936077
In Process

The Archive Base Latest Questions

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

New to Haskell so sorry if this is very basic This example is taken

  • 0

New to Haskell so sorry if this is very basic

This example is taken from “Real World Haskell” –

ghci> :type fst  
fst :: (a, b) -> a

They show the type of the fst function and then follow it with this paragraph…

“The result type of fst is a. We’ve already mentioned that parametric polymorphism makes the real type inaccessible: fst doesn’t have enough information to construct a value of type a, nor can it turn an a into a b. So the only possible valid behaviour (omitting infinite loops or crashes) it can have is to return the first element of the pair.”

I feel like I am missing the fundamental point of the paragraph, and perhaps something important about Haskell. Why couldn’t the fst function return type b? Why couldn’t it take the tuple as a param, but simply return an Int ( or any other type that is NOT a)? I don’t understand why it MUST return type a?

Thanks

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

    If it did any of those things, its type would change. What the quote is saying is that, given that we know fst is of type (a, b) -> a, we can make those deductions about it. If it had a different type, we would not be able to do so.

    For instance, see that

    snd :: (a, b) -> a
    snd (x, y) = y
    

    does not type-check, and so we know a value of type (a, b) -> a cannot behave like snd.

    Parametricity is basically the fact that a polymorphic function of a certain type must obey certain laws by construction — i.e., there is no well-typed expression of that type that does not obey them. So, for it to be possible to prove things about fst with it, we must first know fst‘s type.

    Note especially the word polymorphism there: we can’t do the same kind of deductions about non-polymorphic types. For instance,

    myFst :: (Int, String) -> Int
    myFst (a, b) = a
    

    type-checks, but so does

    myFst :: (Int, String) -> Int
    myFst (a, b) = 42
    

    and even

    myFst :: (Int, String) -> Int
    myFst (a, b) = length b
    

    Parametricity relies crucially on the fact that a polymorphic function can’t “look” at the types it is called with. So the only value of type a that fst knows about is the one it’s given: the first element of the tuple.

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

Sidebar

Related Questions

I am really new to Haskell (Actually I saw Real World Haskell from O'Reilly
I am new to Haskell, sorry if this is a basic question. I currently
Sorry if the question is very elementary, I am still very new to Haskell.
I'm new to Haskell, so am sorry if this is incredibly obvious... I have
I am new to Haskell and I am reading the book Real World Haskell
I am new to Haskell and this mixture of Infix and Prefix notation is
I am new to Haskell and I wonder how/if I can make this code
I am very new in haskell, i wrote the code for item details and
This is my first posting on SO, and I'm relatively new to Haskell, so
I'm working through Real World Haskell one of the exercises of chapter 4 is

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.