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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:27:51+00:00 2026-06-13T14:27:51+00:00

Using the following type and class definitions, I do not understand why I get

  • 0

Using the following type and class definitions, I do not understand why I get and error when creating the instance below.

I need MyMap to hold a map of heterogeneous values.

{-# LANGUAGE ExistentialQuantification #-}
module Scratch.SO_ExtistentialTypes where

import Data.Map

type MyMap a = Map String a

class MyClass c where 
    getMyMap :: forall a. c -> MyMap a

data MyData = forall a. MyData {
    myMap ::  MyMap a
}

instance MyClass MyData where
    getMyMap = myMap -- <= ERROR
  • 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-13T14:27:52+00:00Added an answer on June 13, 2026 at 2:27 pm

    For one thing, the forall here is superfluous:

    class MyClass c where 
        getMyMap :: forall a. c -> MyMap a
    

    Type variables with no explicit binding are universally quantified at the outermost level, so this is exactly the same as just c -> MyMap a.

    Beyond that, a universally quantified type is certainly not going to match an existentially quantified type. The type of getMyMap says that, given a value of type c, it will produce a value of type MyMap a for any possible choice of type a. On the other hand, the accessor myMap says that, given a value of type MyData, it will produce a value of type MyMap a for some specific but unknown type a.

    It’s not possible to have unwrapped existential types floating around by themselves (this would require an exists quantifier corresponding to forall), so there’s no way to rewrite the type of getMyMap such that myMap is a valid implementation.

    All you can do with something having an existential type is wrap it back up in another data type that hides the existential quantifier, or give it to a function that has an argument with a universally quantified type. For example, you can use length on a list [a] with a an existential type.

    In your case, the values of the Map have existential type with no other structure or constraints, so they’re pretty much useless and might as well be ().

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

Sidebar

Related Questions

Using the following Webservice definition using aClientArgs as a complex type: [System.Web.Script.Services.ScriptService] public class
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Simple enough question I hope. I am using the following type of code to
When using ASP.net webforms my usual solution would have following type of setup -
I've tried to change filenames using following script: find dir/ -type f -exec mv
I am successfully instantiating/automating Visual Studio using the following code: System.Type t = System.Type.GetTypeFromProgID(VisualStudio.DTE.9.0);
I tried to modify a type using the following code and it gave me
Is there an equivalent to the following: header(Content-type: text/xml); I'm using Google Maps with
I'm following the instructions on using xsi:type from this oft-cited blog post: http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-xsitype.html Basically
I have the following code to convert the type of the matrix using cv::Mat.convertTo()

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.