What's new

How to retrieve data from a list of different data type in haskell

Fever

Active member
Staff member
How do we retrieve specific data from a list of two different data type? The program only recognizes these chocolate and candy as 1 argument and not as two. Is there another better way of retrieving it?

data Store = Cookie Sweets [(Chocolate, Candy)]

-- get Candy Chocolate
getChocolate :: Store -> [(Chocolate, Candy)]
getChocolate (Store _ _ ch) = ch

-- get Candy Chocolate
getCandy :: Store -> [(Chocolate, Candy)]
getCandy (Store _ _ ca) = ca

Continue reading...
 
Top