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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:00:59+00:00 2026-06-15T11:00:59+00:00

in this period I am learning Haskell but I have problems solving a simple

  • 0

in this period I am learning Haskell but I have problems solving a simple exercise.

I would like to write a simple associative map data structure to exercise myself.

This is the code I have written so far:

-- It represents a simple ordered couple in the form (key, value)
data Element a b = Element (a, b)
    deriving (Show)

-- It represents a (unordered) list of elements in the form (key, value)
data Dictionary a b = Dictionary [Element a b]
    deriving (Show)

-- It represents a simple dictionary which will be used for my tests
t :: Dictionary Char Int
t = Dictionary [Element ('a', 1), Element ('b', 2), Element ('a', 3)]

Now I am trying to write a simple method to return a list of couples in the form (a, b). I am doing it to exercise myself and to provide a simple function which would be useful for the other methods (find, etc.).

I have written this piece of code but I know it’s wrong:

couples :: Dictionary a b -> [(a, b)]
couples (Dictionary t) = [(k , v) | (k, v) <- t]

The problem is that obviously “t” is not a list of couples: it’s composed by a list of elements which are composed by a type constructor “Element” followed by an ordered couple.

How could I “get rid” of the “Element” type constructor? I have no idea…

Thank you in advance.

  • 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-06-15T11:01:00+00:00Added an answer on June 15, 2026 at 11:01 am

    Just add the Element constructor in the pattern-match.

    couples :: Dictionary a b -> [(a, b)]
    couples (Dictionary t) = [(k , v) | (Element (k, v)) <- t]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not homework, just a learning exercise on my part. I have been
this is my first question in here, and I would like to ask if
This should be a simple one: I have an observableArray object called To in
I inherited a horribly-designed table where data is stored like this: Period | Identifier
I have one question regarding trigger. The scenario is like this Create Procedure begin
I have never used ClearCase, but have used Subversion and for a short period
i have developed ads website but i have problem, i want make period from
I am trying to have information displayed for this query: SELECT o.sub_number,o.unique_id,o.period_from,o.period_to,o.total_amt, i.paid_amt,i.dated,i.payment,i.paid_by,i.entered_date,i.paid_for_unique, j.cheque_num,j.drawn_on,j.dated
I need to display a text like this on my PDF using iTextSharp Recommendation
This is a very basic question - but apparently google is not very good

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.