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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:11:03+00:00 2026-05-29T21:11:03+00:00

I have a general idea of what existential quantification on types is and where

  • 0

I have a general idea of what existential quantification on types is and where it can be used. However from my experiences so far, there are a lot of caveats that need to be understood in order to use the concept effectively.

Question: Are there any good resources explaining how existential quantification is implemented in GHC? I.e.

  • How does unification on existential types work – what is unifiable and what is not?
  • In what order subsequent operations on types are performed?

My aim is to better understand error messages that GHC throws at me. Messages usually say something along the lines "this type using forall and this other type don't match", however they don’t explain why it is so.

  • 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-29T21:11:04+00:00Added an answer on May 29, 2026 at 9:11 pm

    The nitty-gritty details are covered in papers from Simon Peyton-Jones, though it takes a good deal of technical expertise to understand them. If you want to read a paper on how Haskell type inference works, you should read about generalized algebraic data types (GADTs), which combine existential types with several other features. I suggest “Complete and Decidable Type Inference for GADTs”, on the list of papers at http://research.microsoft.com/en-us/people/simonpj/.

    Existential quantification actually works a lot like universal quantification. Here is an example to highlight the parallels between the two. The function useExis is useless, but it’s still valid code.

    data Univ a = Univ a
    data Exis = forall a. Exis a
    
    toUniv :: a -> Univ a
    toUniv = Univ
    
    toExis :: a -> Exis
    toExis = Exis
    
    useUniv :: (a -> b) -> Univ a -> b
    useUniv f (Univ x) = f x
    
    useExis :: (forall a. a -> b) -> Exis -> b
    useExis f (Exis x) = f x
    

    First, note that toUniv and toExis are nearly the same. They both have a free type parameter a because both data constructors are polymorphic. But while a appears in the return type of toUniv, it doesn’t appear in the return type of toExis. When it comes to the kind of type errors you might get from using a data constructor, there’s not a big difference between existential and universal types.

    Second, note the rank-2 type forall a. a -> b in useExis. This is the big difference in type inference. The existential type taken from the pattern match (Exis x) acts like an extra, hidden type variable passed to the body of the function, and it must not be unified with other types. To make this clearer, here are some wrong declarations of the last two functions where we try to unify types that shouldn’t be unified. In both cases, we force the type of x to be unified with an unrelated type variable. In useUniv, the type variable is part of the function type. In useExis, it’s the existential type from the data structure.

    useUniv' :: forall a b c. (c -> b) -> Univ a -> b
    useUniv' f (Univ x) = f x -- Error, can't unify 'a' with 'c'
                              -- Variable 'a' is there in the function type
    
    useExis' :: forall b c. (c -> b) -> Exis -> b
    useExis' f (Exis x) = f x -- Error, can't unify 'a' with 'c'.
                              -- Variable 'a' comes from the pattern "Exis x",
                              -- via the existential in "data Exis = forall a. Exis a".
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a general idea, and there are some obvious cases, but there are
To have a general-purpose documentation system that can extract inline documentation of multiple languages,
I have a general idea of what an AST is, but I want to
I have a back-end service that creates unique identifiers for resources. The general idea
I'm playing with IOKit and have the following code, the general idea is to
I have a general idea of how the Garbage Collector works in Java, but
I read about creating user groups, I think I have the general idea. For
I have an idea for a iOS app. However, as I lack the required
So, I've read the android AIDL documentation and have a general idea of how
I think the general idea of PHP being able to have common integer 64-bit

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.