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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:08:08+00:00 2026-05-28T01:08:08+00:00

In this code I am trying to have the first parameter in my worker

  • 0

In this code I am trying to have the first parameter in my worker function go be a ‘type family’ type. I see that in the type type families documentation a similar insert function belongs to the type class, while in my example below it does not.

I am new to type families so maybe I am using them wrong, but what does this error mean?

{-# LANGUAGE TypeFamilies #-}

-- | key
class K a where
  -- | iterator for key
  type I a :: *
  mkI :: a -> I a

--| A map
data (K a) => M a b = M a b

insert :: (K a) => a -> b -> M a b -> M a b
insert = go mkI    -- <<< PROBLEM
  where
    go o a b m = m

Ambiguous type variable `a’ in the constraint:

`K a'

  arising from an expression type signature at Data/Map2.hs:167:10-33

Probable fix: add a type signature that fixes
these type variable(s)

  • 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-28T01:08:09+00:00Added an answer on May 28, 2026 at 1:08 am

    This compiles:

    {-# LANGUAGE TypeFamilies, GADTs, ScopedTypeVariables #-}
    
    -- | key
    class K a where
      -- | iterator for key
      type I a :: *
      mkI :: a -> I a
    
    -- | A map
    data M x y where
        M :: K a => a -> b -> M a b
    
    insert :: forall a b. (K a) => a -> b -> M a b -> M a b
    insert = go mkI
      where
        go :: (a -> I a) -> a -> b -> M a b -> M a b
        go o a b m = m
    

    What have I changed and why?

    First, I assumed that you wanted the constraint on M, so I used a form of type definition that enforces the constraint and makes it available at use sites, a GADT.

    Second, the problem your GHC complained about, the ambiguity. The point is that there’s no way for the compiler to deduce which mkI it should use, so we have to tell it. For that, we must bring the type variables used into scope and then tell the compiler in the local signature which type instance to use.

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

Sidebar

Related Questions

I have this code in my ASP.NET application written in C# that is trying
I'm extremely new to JS and have this code that I'm trying to tweak.
I have got this code and I am trying to understand the convention followed,
I am trying to compare two dates. I have this code which I thought
I am trying to enable mod_deflate. I have Apache 2.0+ and tried this code
I have this piece of code I'm trying to get to display but no
I have this php code, with which I am trying to generate a popup
All, I am trying to code a Connect4 game. For this, I have created
I am trying this code: entLoop:for(var i:*in entities) { for(var i2:*in ignoreEntities) { if(entities[i].type==ignoreEntities[i2])
I have been trying to follow this example (download the source code from a

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.