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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:09:23+00:00 2026-05-21T09:09:23+00:00

here s my question, i need to construct a database representing information about one

  • 0

here s my question, i need to construct a database representing information about one country owning county owning city, using a list of 2-tuples (i.e., pairs)
for example c1 owns c2, which owns c3, which owns c4, but where the “indirect” ownership of c4 by c1 (etc.) is not directly stated.
i need to write a function ‘owns’ which, given two strings naming country returns a Boolean indicating whether the first owns the second (even indirectly, as with the case of c1 and c4 above).
here s my code, and i know it s not quite right, i new very new to haskell ….therefore, need help please….

lst = [("uk","scotland"),("scotland","aberdeen"),("china","hongkong"),("hongkong","kulong")]
owns :: String-> String -> Bool
owns a b 
    | n = lookup a (fromList lst)
        |if b==n 
            return true
        |otherwise m = lookup n (fromlist lst)
            if b==m
            return true
    | otherwise = False

i m expecting the output result should be something like:

Main> owns "uk" "scotland"
True
Main> owns "uk" "aberdeen"
True
Main> owns "uk" "hongkong"
False
  • 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-21T09:09:24+00:00Added an answer on May 21, 2026 at 9:09 am
    owns parent child = parent == child || any (owns parent) [p | (p, c) <- lst, c == child]
    

    You will want to know how this works.

    First, we recognise that this is a recursion question. c1 owns c2 owns c3 owns c4 etc. We don’t know how many steps this could take. So we need a base case and a recursive case.

    The base case is parent == child. If this is True, then the overall answer is True.

    Now, the recursive case. any takes a function and a list, and returns True if any member of the list makes the function return True.

    (I need to sleep now, will come back to this later if needed.)

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

Sidebar

Related Questions

Just a quick question here. I have a program in which I need to
Ok, I need help. This is my first question here. Background: I am working
here's my question: I have an MVC3 C# application and I need to update
I need to develop small AIR extension for iOS. here's the question: is it
So here's my question (i'm using Oracle SQL by the way) I have 3
Per an answer to a previous question (answer here: SQL/Database Views in Grails ),
Yesterday I had a few question about OO and classes in PHP here but
I need some information here. I am totally new at MVC therefore for you
OK, total noob question here. I'm toying around with Silverlight, and need to connect
I need to do something similar to the task described in this question: Construct

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.