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

  • Home
  • SEARCH
  • 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 6545325
In Process

The Archive Base Latest Questions

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

I have a pretty straightforward function that takes a parameterized data type and returns

  • 0

I have a pretty straightforward function that takes a parameterized data type and returns the same type:

{-# LANGUAGE ScopedTypeVariables #-}

class IntegerAsType a where
  value :: a -> Integer

newtype (Num a, IntegerAsType n) => PolyRing a n = PolyRing [a] deriving (Eq) 

normalize :: (Num a, IntegerAsType n) => (PolyRing a n) -> (PolyRing a n)
normalize r@(PolyRing xs) | (genericLength xs) == len = r
                          | ... [other cases]
           where len = (value (undefined :: n))

The idea is that normalize will take a PolyRing with a list of any size and then return a new PolyRing with a padded/modded coefficient vector of length n, where n is part of the type of the PolyRing passed in.

I’m getting the error:

Ambiguous type variable `a0' in the constraint: 
(IntegerAsType a0) arising from a use of `value'

I’ve looked at all of the other SO posts on this error, and still have nothing. The error occurs even if I remove all references to ‘len’ (but keep it in the where clause), so the problem is with

(value (undefined :: n))

which is virtually identical to how I’ve used IntegerAsType in other places.

While you are at it, I’m also taking suggestions for alternatives to the parameterized type system I’m using now. In particular, it is a pain because I have to define IntegerAsType for lots of different values. We are using the types rather than parameters to ensure, for example, that you can’t add two elements of different polynomial rings (the parameter ‘a’ makes sure you can’t add polynomial rings mod the same polynomial but over different underlying rings).

Thanks

  • 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:34:22+00:00Added an answer on May 25, 2026 at 11:34 am

    The signature for normalize doesn’t create the scope for the type variable n in undefined :: n.

    Try this:

    normalize r@(PolyRing xs :: PolyRing a n) | ... = ...
              where len = value (undefined :: n)
    

    Alternatively, you can use an explicit forall in the type signature for normalize:

    normalize :: forall a n . (Num a, IntegerAsType n) => (PolyRing a n) -> (PolyRing a n)
    normalize r@(PolyRing xs) | ... = ...
          where len = value (undefined :: n)
    

    See http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/other-type-extensions.html#decl-type-sigs

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

Sidebar

Related Questions

OK, this begins to drive me crazy. I have an asp.net webapp. Pretty straightforward,
I have pretty big background of .net, and I've decided that i want to
I have a pretty complicated Linq query that I can't seem to get into
Pretty straight forward question, I have a GtkEntry widget that I want to set
So pretty straightforward question. I have a c# .dll with a whole lot of
I have a side project I do = in Java. It's a pretty straight-forward
I have pretty much finished my first working Symbian application, but in my hastened
I would like to have pretty URLs for my tagging system along with all
I have a pretty standard table set-up in a current application using the .NET
I have a pretty basic windows form app in .Net. All the code is

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.