I'm writing a movie database with Haskell. Like the title says, I am trying to give (without duplicates) the names of actors who have co-starred in at least one film with a particular actor.
Here's my code until now:
import Text.Printf
import Data.List
import Data.Ord
import Data.Foldable
type Title = String
type Actor = String
type Cast = [Actor]
type Year = Int
type Fan = String
type Fans = [Fan]
type Period = (Year, Year)
data Film = Film Title Cast Year Fans
deriving(Show,Read,Eq)
testDatabase :: [Film]
testDatabase = [(Film "Casino Royale" ["Daniel Craig", "Eva Green", "Judi Dench"] 2006 ["Garry", "Dave", "Zoe", "Kevin", "Emma"]),
(Film "Cowboys & Aliens" ["Harrison Ford", "Daniel Craig", "Olivia Wilde"] 2011 ["Bill", "Jo", "Garry", "Kevin", "Olga", "Liz"]),
(Film "Catch Me If You Can" ["Leonardo DiCaprio", "Tom Hanks"] 2002 ["Zoe", "Heidi", "Jo", "Emma", "Liz", "Sam", "Olga", "Kevin", "Tim"]),
(Film "Mamma Mia!" ["Meryl Streep", "Pierce Brosnan", "Colin Firth"] 2008 ["Kevin", "Jo", "Liz", "Amy", "Sam", "Zoe"]),
(Film "Titanic" ["Leonardo DiCaprio", "Kate Winslet"] 1997 ["Zoe", "Amy", "Heidi", "Jo", "Megan", "Olga"]),
(Film "Quantum of Solace" ["Daniel Craig", "Judi Dench"] 2008 ["Bill", "Olga", "Tim", "Zoe", "Paula"])]
coactors :: Actor -> [Film] -> [Actor]
coactors [] = []
coactors a -> filter (/= a) . nub . concatMap (\(Film _ c _ _) -> if a `elem` c then c else [])
This is my try for a function that does what I said above. It doesn't work, and I don't know why. Can anyone provide me with correction that will make the function work?