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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:36:56+00:00 2026-05-25T19:36:56+00:00

There are several data types. data Book =BName| Author deriving (Eq,Show) data Video =

  • 0

There are several data types.

data Book =BName| Author deriving (Eq,Show)
data Video = VName deriving (Eq,Show)
data CD =Cname | Auth | NOC deriving (Eq,Show)
data Product = Product Book Video CD deriving (Eq,Show)

make function getTitle which return the name(BName,CName or VName) of structure.
For example
getTitle (Book “name “noname”) -> “name”
getTitle (Vide “name”) -> “name”
and etc.

Is it possible?

Exist data type Book with fields title and author,Videocassete with field author, CDdisk with fields title,number of compositions and author.
1)create data type Product which can introduce this data types
2)make function getTitle which returns titles.
3)make function getTitles which returns all titles in the list of products(use function getTtitle)
4)make function bookAuthors which return books’ authors in the list of products
5)make function lookupTitle::String->[Product]->Maybe Product which returns product with input name
6)make function lookupTitles::[String]->[Product]->[Product] which input params are the list of names and the list of products and for every name it gets products from list of products. Ignor names in the first list without products in the second list for them.Use function lookipTitle.

That’s all task.


data Book = Book String String deriving(Eq,Show)
data Video = Video String deriving(Eq,Show)
data CDisk = CDisk String String Int deriving(Eq,Show)
--titles
class Titleable a where
 getTitle :: a ->String
instance Titleable Book where
 getTitle (Book title _) = title
instance Titleable Video where
 getTitle (Video title) = title
instance Titleable CDisk where
 getTitle(CDisk title _ _) = title
--get titles
getTitles (x:xs) = [ getTitle x | x<-xs ]
lookupTitle _ [] =Nothing
lookupTitle::String->[Product]->Maybe Product
lookupTitle a (x:xs)  | getTitle x==a =Just x
                             | otherwise = lookupTitle a (x:xs)
lookupTitles::[String]->[Product]->[Product]
lookupTitles (x:xs) (y:ys) = [y|x<-xs,y<-ys,x==lookupTitle y]

but
1)I don’t know how to make function bookAuthors(how can function find that the parameter is book-type?)
2)how to make Product type?I mean it is either Book or Video or CDisk
3)lookupTitle and lookupTitle are correct?

  • 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-25T19:36:57+00:00Added an answer on May 25, 2026 at 7:36 pm

    Are you sure you want the data types like this?

    data Book = BName | Author deriving (Eq,Show)
    

    Means a Book is either a BName (book name?) or an Author?

    I suspect you want something similar to

    data Book = Book BName Author
    

    e.g. a book has a book name and an author

    If you want to capture the essence of “titleable” things you could use type classes.

    class Titleable a where
      getTitle :: a -> String
    
    instance Titleable Book  where
      getTitle (Book title _) = title
    

    And write instances for your other types.

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

Sidebar

Related Questions

There are several possible ways of getting the path to the application data directory:
There are several similar Oracle technologies - Oracle Streams, Oracle Change Data Capture and
So, there have been several posts here about importing and saving data from an
In my ViewModels I use several DataAnnotations to validate the form data, there are
There are several types of objects in a system, and each has it's own
I'm trying to create some search functionality across several types of data, with autocomplete.
I have a DataTable which I select from database (Well, these data cross several
Lets say I need to write several functions processing some data. These functions are
There are several ways to iterate over a result set. What are the tradeoff
There are several plugin options for building a search engine into your Ruby on

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.