This expression:
sort words "fire water earth fire"
— gives this error —
Couldn't match expected type `[a]'
against inferred type `GHC.Base.String -> [GHC.Base.String]'
Could someone explain to me what is going on here and how to elegantly express sort.words?
You want this:
when you do
it’s actually doing
sortexpects a list ([a]), but you’re instead giving itwords, which is a function takes a string and returns a list of strings (String -> [String]), hence the error message (it can’t treatString -> [String]as a list of anything).You can also do this:
which is equivalent to the first version and might look neater.