A higher-order function is a function that takes another function as an argument, produces another function as a result, or perhaps both.
The function in your question has a single argument that is a string, not a function. When applied, your function’s value is an array of strings, not a function. Therefore, it is an ordinary function.
A similar function that is higher order is
sortString :: (Char -> Char -> Ordering) -> String -> [String]
sortString cmp s = map (:[]) $ sortBy cmp s
The power of higher-order functions is the flexibility they provide. Providing different functions produces different results:
ghci> sortString compare "slkdjfs"
["d","f","j","k","l","s","s"]
ghci> sortString (flip compare) "slkdjfs"
["s","s","l","k","j","f","d"]
In case you aren’t familiar, compare
provides an Ordering
relative to its arguments, e.g.,
ghci> compare 'a' 'b'
LT
ghci> compare 'b' 'a'
GT
As you may have noticed, flip
is itself another higher-order function that reorders or flips the arguments to another function. Using flip
as in the code above allows us to sort the list in descending rather than ascending order.
String
and returns a list ofString
, so it's not higher order. However, if your sort function also took a function (like a comparison operator to determine ordering), then it would be higher-order.a -> b -> c
is the same asa -> (b -> c)
. This means defining higher-order functions as returning a function is too broad--it would even include things like(+)
!(τ₁ → τ₂) → τ₃
, and is probably the most applicable one for Haskell.