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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:17:37+00:00 2026-05-13T19:17:37+00:00

The purpose for this particular portion of code is to make the size function

  • 0

The purpose for this particular portion of code is to make the size function more efficient than simply counting all the elements in elems. I’ve settled on summing the two types that make up the list, but I can’t seem to create the signature of the size function.

instance (Finite a, Finite b) => Finite (Either a b) where
    elems = combineLists [Left x | x <- elems] [Right x | x <-elems]
    size ??? = (size a) + (size b)

From Prelude, we know that Either a b = Left a | Right b.

The first thing I tried was to match Either, but of course it is a type, so that doesn’t work. Next, I tried ((Left a) | (Right b)), but no go on that either. Nothing else seems to match the type Either a b.

I was able to get size (Left a) to compile, but since it’s missing the b component, I receive the error:

Ambiguous type variable `b' in the constraint:
  `Finite b' arising from a use of `size' at <interactive>:1:0-12

which of course makes sense in the context, but I really have no clue how to match Either a b.

Anybody have any thoughts?

  • 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-13T19:17:37+00:00Added an answer on May 13, 2026 at 7:17 pm

    Something of type Either a b is either a Left a or a Right b, so you have two cases that can be handled separately:

    size (Left x) = size x
    size (Right x) = size x
    

    The error about the ambiguous type variable is a separate issue.
    If you just type something like size (Left 1) into the interpreter, the system can’t deduce what the “right” type of that Left 1 value would be. It could be Either Int anything and as long as it is not known what type that anything is, it cannot be checked if it is in class Finite (which is required by size).

    You can avoid that problem by specifying an explicit type signature:

    size (Left 1 :: Either Int String)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 409k
  • Answers 409k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, the warning says: dependent name is not a type.… May 15, 2026 at 7:08 am
  • Editorial Team
    Editorial Team added an answer This is an automatically generated wrapper around the Outlook COM… May 15, 2026 at 7:08 am
  • Editorial Team
    Editorial Team added an answer Put the database outside the website directory, then refer to… May 15, 2026 at 7:08 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.