Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List
- main :: IO()
- main = do
- print $ rf (Song "Mozart""The Marriage of Figaro Overture" 270) -- == "Summertime"
- print $ rf (Song "Gershwin""Summertime" 300) -- == "Rhapsody in Blue"
- print $ rf (Song "Gershwin""Rhapsody in Blue" 1100) -- == "Rhapsody in Blue"
- type SongName = String
- songs = [
- (Song "Mozart""The Marriage of Figaro Overture" 270),
- (Song "Gershwin""Summertime" 300),
- (Song "Queen""Bohemian Rhapsody" 355),
- (Song "Gershwin""Rhapsody in Blue" 1100)]
- type AuthorName = String
- type SongLength = Int
- data Song = Song AuthorName SongName SongLength -- that is the main line we need
- deriving (Eq, Show)
- data Playlist = Playlist [Song]
- rf = recommender (Playlist songs)
- -- aN = authorName, sN = songName, sL = songLength
- -- pl is a list, actually it represented PlayList
- -- we are gonna split function in two parts
- -- in the first we need to have filter and dropWhile
- -- in the second part we are just gonna need filter
- recommender :: Playlist -> (Song -> SongName)
- recommender (Playlist pl) = (\p@(Song aN sN sL) -> if null $ recommendALgorithm1 aN sL then if null $ recommendAlgorithm2 aN sL then p else head recommendAlgorithm2 aN sL else head $ recommendALgorithm1 aN sL)
- where
- -- here we need to use filter and dropWhile, and check if length is bigger, if it's bigger than we move on to another fucntion
- recommnedAlgorithm1 :: AuthorName -> Int ->
- recommendAlgorithm1 aN l = filter (\(Song authorName sN sL) -> sL > l && aN == authorName) pl
- recommentAlgorithm2 :: AuthorName -> Int ->
- recommendAlgorithm2 aN l = (\p@(Song authorName sN sL) -> if length (dropWhile (/= p) pl) < 1 then p else head $ tail recommendAlgorithm2 aN l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement