firstly i want to ask where can i look to improve my skills with haskell, whenever i get stuck i cant find relevant tutorials or anything to help me, im using trial and error to figure out syntax for things and its frustrating, i can ask for help with each problem here but i feel like a nuisance and that there should be other routes first like when i program in C# or Python i can usually search around for similar problems and solve it myself, but less so with Haskell, so any tutorials, wisdom, courses or whatever would be greatly appreciated! (im creating a data type and wish to manipulate a list of those types through a variety of functions)
the error i keep having is mismatched types with the expected types.
data Song = Song {title :: String,
artist :: String,
sales :: Int} deriving(Eq, Show)
database :: [Song]
database = [s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22]
s1 = Song "Amon Amarth" "Ravens flight" 1 --this seems... inefficient lots of repetition here...
s2 = Song "Amon Amarth" "Shield wall" 11
s3 = Song "Amon Amarth" "The way of vikings" 105
s4 = Song "Elijah Nang" "Journey to the west" 1000
s5 = Song "Elijah Nang" "Tea house" 7
s6 = Song "Pink Floyd" "Wish you were here" 123
s7 = Song "Amon Amarth" "Raise your horns" 9001
s8 = Song "NLE Choppa" "Walk 'em down'" 69420
s9 = Song "Elijah Nang" "Kumite" 1337
s10 = Song "NLE Choppa" "Shotta flow 6" 511
s11 = Song "Pink Floyd" "Comfortably numb" 9
s12 = Song "Pink Floyd" "Shotta flow 6" 711 -- changed to match the name of an nle choppa song as requested
s13 = Song "Johannes Chrysostomus Wolfgangus Theophilus Mozart" "Requiem" 10203948
s14 = Song "Elijah Nang" "Kenjutsu water style" 1
s15 = Song "NLE Choppa" "Shotta flow 5" 1
s16 = Song "Pink Floyd" "High hopes" 1
s17 = Song "Amon Amarth" "Deceiver of the gods" 1
s18 = Song "Johannes Chrysostomus Wolfgangus Theophilus Mozart" "Turkish march" 1
s19 = Song "Chance The Rapper" "Cocoa butter kisses" 1
s20 = Song "Chance The Rapper" "Favourite song" 1
s21 = Song "Chance The Rapper" "Hot shower" 1
s22 = Song "Chance The Rapper" "High hopes" 1
-- give this function an index of 0 every time to start with, give it a artist and a track, then it will output the sales for that track of the artist
getTrackSale :: Int -> String -> String -> Int --(index, artist, track, sales)
getTrackSale index artist track
| ((getArtist(database!!index) == artist) && (getTrack(database!!index) == track)) = getTrackSale(database!!index)
| otherwise = getTrackSale(index+1 artist track)
task2 = getTrackSale(0 "Chance The Rapper" "Hot Shower") --uses index 0, and that artist + track, should return the stored sales for that combo.
getArtist :: Song -> String
getArtist (Song y _ _) = y
getTrack :: Song -> String
getTrack (Song _ z _) = z
getSale :: Song -> Int
getSale (Song _ _ x) = x
this give me the error of
123.hs:42:88: error:
* Couldn't match expected type `Int'
with actual type `String -> String -> Int'
* Probable cause: `getTrackSale' is applied to too few arguments
In the expression: getTrackSale (database !! index)
In an equation for `getTrackSale':
getTrackSale index artist track
| ((getArtist (database !! index) == artist)
&& (getTrack (database !! index) == track))
= getTrackSale (database !! index)
| otherwise = getTrackSale (index + 1 artist track)
|
42 | | ((getArtist(database!!index) == artist) && (getTrack(database!!index) == track)) = getTrackSale(database!!index)
it sounds like it's confusing what input variables i want to give and what output variables i want, i don't know what i'm doing wrong.