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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:37:45+00:00 2026-05-25T11:37:45+00:00

Consider the following code, data MyBaseExpr α where ConstE :: Show α => α

  • 0

Consider the following code,

data MyBaseExpr α where
    ConstE :: Show α => α -> MyBaseExpr α

class Monad  => MyMonadCls  where
    type ExprTyp  :: * -> *
    var :: String -> ExprTyp  α ->  (ExprTyp  α)

expTypArg :: forall  α. MyMonadCls  => ExprTyp  α ->  α
expTypArg a = undefined

-- dummy type which will be used as an instance
newtype A  α = A ( α)

Then, if one tries to write an instance using the expTypeArg function,

instance forall . (Monad , Monad (A )) => MyMonadCls (A ) where
    type ExprTyp (A ) = MyBaseExpr
    var nme init@(expTypArg -> typb) =
        return init

the compiler complains

Couldn't match type `ExprTyp 0' with `MyBaseExpr'
Expected type: ExprTyp (A ) α
  Actual type: ExprTyp 0 α

But, if one adds some scoped type expressions,

instance forall . (Monad , Monad (A )) => MyMonadCls (A ) where
    type ExprTyp (A ) = MyBaseExpr
    var nme init@((expTypArg :: MyMonadCls (A ) =>
                   ExprTyp (A ) α ->
                   (A  α)) -> typb) =
        return init

then it resolves fine. What’s the problem resolving ExprTyp == MyBaseExpr for expTypArg?

edit

Thanks very much, Daniel! Here’s a way to take some of the verbage out, after noticing that only the type of need be enforced.

ignore_comp ::  α ->  β ->  β
ignore_comp a b = b

instance forall . (Monad , Monad (A )) => MyMonadCls (A ) where
    type ExprTyp (A ) = MyBaseExpr
    var nme init@(expTypArg -> typb) =
        typb `ignore_comp`
        return init
  • 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-25T11:37:45+00:00Added an answer on May 25, 2026 at 11:37 am

    ExprTyp is not (necessarily) an injective type function. This means that being handed something of type ExprType m doesn’t nail down m — there may also be a different n such that ExprType n = ExprType m. This makes the type of expTypArg a bit tricky: it uses return-type polymorphism in the same way, e.g., read does, so you’ll need to give extra type annotations to its result in the same situations you have to do with read.

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

Sidebar

Related Questions

Consider the following code: public abstract class Test1 { public object Data { get;
Consider the following code: client.Send(data, data.Length, endpoint); byte[] response = client.Receive(ref endpoint); While, according
Consider the following code and its output: Code #!/usr/bin/perl -w use strict; use Data::Dumper;
Consider the following code: abstract class SomeClassX<T> { // blah } class SomeClassY: SomeClassX<int>
Consider the following code snippet private void ProcessFile(string fullPath) { XmlTextReader rdr = new
Consider the following code: require(Hmisc) num.boots <- 10 data <- rchisq(500, df = 5)
Please consider the following code, <form action=index.php method=post name=adminForm enctype=multipart/form-data> <input type=hidden name=showtime[] id=showtime_1
Consider the following code snippet within a class private static Object _syncroot = new
Consider the following code. public interface IFoo { } public class Bar { public
Consider following code for an android app; private String GetDistance(String src, String dest) {

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.