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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:03:15+00:00 2026-06-17T07:03:15+00:00

What exactly is the difference between these? I think I understand how existential types

  • 0

What exactly is the difference between these? I think I understand how existential types work, they are like having a base class in OO without a way to down cast. How are universal types different?

  • 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-17T07:03:16+00:00Added an answer on June 17, 2026 at 7:03 am

    The terms “universal” and “existential” here come from the similarly-named quantifiers in predicate logic.

    Universal quantification is normally written as ∀, which you can read as “for all”, and means roughly what it sounds like: in a logical statement resembling “∀x. …” whatever is in place of the “…” is true for all possible “x” you could choose from whatever set of things is being quantified over.

    Existential quantification is normally written as ∃, which you can read as “there exists”, and means that in a logical statement resembling “∃x. …” whatever is in place of the “…” is true for some unspecified “x” taken from the set of things being quantified over.

    In Haskell, the things being quantified over are types (ignoring certain language extensions, at least), our logical statements are also types, and instead of being “true” we think about “can be implemented”.

    So, a universally quantified type like forall a. a -> a means that, for any possible type “a”, we can implement a function whose type is a -> a. And indeed we can:

    id :: forall a. a -> a
    id x = x
    

    Since a is universally quantified we know nothing about it, and therefore cannot inspect the argument in any way. So id is the only possible function of that type(1).

    In Haskell, universal quantification is the “default”–any type variables in a signature are implicitly universally quantified, which is why the type of id is normally written as just a -> a. This is also known as parametric polymorphism, often just called “polymorphism” in Haskell, and in some other languages (e.g., C#) known as “generics”.

    An existentially quantified type like exists a. a -> a means that, for some particular type “a”, we can implement a function whose type is a -> a. Any function will do, so I’ll pick one:

    func :: exists a. a -> a
    func True = False
    func False = True
    

    …which is of course the “not” function on booleans. But the catch is that we can’t use it as such, because all we know about the type “a” is that it exists. Any information about which type it might be has been discarded, which means we can’t apply func to any values.

    This is not very useful.

    So what can we do with func? Well, we know that it’s a function with the same type for its input and output, so we could compose it with itself, for example. Essentially, the only things you can do with something that has an existential type are the things you can do based on the non-existential parts of the type. Similarly, given something of type exists a. [a] we can find its length, or concatenate it to itself, or drop some elements, or anything else we can do to any list.

    That last bit brings us back around to universal quantifiers, and the reason why Haskell(2) doesn’t have existential types directly (my exists above is entirely fictitious, alas): since things with existentially quantified types can only be used with operations that have universally quantified types, we can write the type exists a. a as forall r. (forall a. a -> r) -> r–in other words, for all result types r, given a function that for all types a takes an argument of type a and returns a value of type r, we can get a result of type r.

    If it’s not clear to you why those are nearly equivalent, note that the overall type is not universally quantified for a–rather, it takes an argument that itself is universally quantified for a, which it can then use with whatever specific type it chooses.


    As an aside, while Haskell doesn’t really have a notion of subtyping in the usual sense, we can treat quantifiers as expressing a form of subtyping, with a hierarchy going from universal to concrete to existential. Something of type forall a. a could be converted to any other type, so it could be seen as a subtype of everything; on the other hand, any type could be converted to the type exists a. a, making that a parent type of everything. Of course, the former is impossible (there are no values of type forall a. a except errors) and the latter is useless (you can’t do anything with the type exists a. a), but the analogy works on paper at least. :]

    Note that the equivalence between an existential type and a universally quantified argument works for the same reason that variance flips for function inputs.


    So, the basic idea is roughly that universally quantified types describe things that work the same for any type, while existential types describe things that work with a specific but unknown type.


    1: Well, not quite–only if we ignore functions that cause errors, such as notId x = undefined, including functions which never terminate, such as loopForever x = loopForever x.

    2: Well, GHC. Without extensions, Haskell only has the implicit universal quantifiers and no real way of talking about existential types at all.

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

Sidebar

Related Questions

I am trying to understand the difference between these four methods. I know by
I think I understand the difference between ASCII mode and Binary mode on regular
I am wondering, What's exactly the difference between these two ways of initializing an
foo(); (*foo)(); (&foo)(); What exactly is the difference between these function calls (assuming foo()
What exactly is the difference in rails between dev and prod environments. When I
What is the difference between PrintStream and PrintWriter ? They have many methods in
Recently I've been thinking about performance difference between class field members and method variables.
I'm trying to understand the difference between rows created using the following methods: newTable.Rows.Add(array);
One thing I'm a bit unclear on is the difference between these NSMutableArray Methods:
I tried to find what the difference is between these two with Google, but

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.