Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove type from type list haskell

So i'm new to Haskell, and I was wondering if anyone could help me.

I've got a list of a custom data type like so:

type Title = String
type Manager = String
type Year = Int
type Fan = String
type Album = (Title, Manager, Year, [Fan])

And I have a pre-made static database of albums

albumDatabase :: [Album]
albumDatabase = [(...)]

And I have a function that returns all albums that a manager has made:

manAlbum :: String -> [Album] -> [Album]
manAlbum d database = filter ((\(_,album,_,_) -> d == album)) database

My question is, from this new list of all the managers albums, I need to retrieve only the fans and drop the Title, Manager and Year. However I am unsure of how to tell haskell that I only want this field from the custom datatype to be returned.

like image 492
FracturedPixel Avatar asked Nov 30 '25 16:11

FracturedPixel


1 Answers

As 4castle mentioned, you can use map:

getAlbumFans :: [Album] -> [[Fan]]
getAlbumFans database = map (\(_,_,_,fans) -> fans) database

Also you could make the manAlbum function more readable by giving it a more descriptive name like getAlbumsByManager and replacing String in the type signature with Manager.

like image 125
rubystallion Avatar answered Dec 02 '25 06:12

rubystallion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!