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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:39:34+00:00 2026-05-24T18:39:34+00:00

Suppose I have a compound data type – data M o = M (String,o)

  • 0

Suppose I have a compound data type –

data M o = M (String,o)

Now, I can define a function that works for ALL M irrespective of o. For example –

f :: M o -> M o
f (M (s,o)) = M (s++"!", o)

However, f is not really as general as I’d like it to be. In particular, using f in an expression fixes the type of o so I cannot use f again with a different type of o. For example the following does not typecheck –

p f = undefined where
  m1 = M ("1", ())
  m2 = M ("2", True)
  m1' = f m1
  m2' = f m2

It produces the error – Couldn't match expected type 'Bool' with actual type '()'

Surprisingly, if I don’t provide f as an argument and instead simply use the global definition of f then it compiles and works fine! i.e. this compiles –

p = undefined where
  m1 = M ("1", ())
  m2 = M ("2", True)
  m1' = f m1
  m2' = f m2

Is there a particular reason for this? How can I work around this problem i.e. define a function f that can be applied to all (M o), even when the o varies within the same expression? I’m guessing existential types come into play here but I just can’t figure out how.

  • 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-24T18:39:35+00:00Added an answer on May 24, 2026 at 6:39 pm

    The problem is that the compiler cannot infer the type of p properly. You’ll have to give it a type signature:

    p :: (forall o. M o -> M o) -> a
    

    This is a rank 2 type, so you’ll need a language extension:

    {-# LANGUAGE Rank2Types #-}
    

    or

    {-# LANGUAGE RankNTypes #-}
    

    Read more about it here: http://www.haskell.org/haskellwiki/Rank-N_types

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

Sidebar

Related Questions

Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Suppose I have a data array, dat <- array(NA, c(115,45,10)) How can I get
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have a table called Companies that has a DepartmentID column. There's also
Suppose you have a window with multiple buttons such as Ok/Cancel or Yes/No/Cancel. All
Suppose you have the following... An ASP.NET web application that calls a stored procedure
Suppose you have a file that you are programmatically logging information into with regards
Suppose we have some class A that implements some interface I I i =
Suppose I have logged into an application which is running from IIS . Now
Suppose you have a profile for an application. This profile stores some data specifically

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.