Why is take a total function

haskell, partial-functions

Solution

`take` and `drop` are similar to the left-substring and right-substring functions, and it's proven in practice to be convenient for those not raise an error for negative or invalid lengths.

For example - a padding function:

pad :: Int -> String -> String
pad n str = (repeat (n - length str) ' ') ++ str

and here is a variant to pad with another string:

padWith :: String -> Int -> String -> String
padWith field n str = (take (n - length str) field) ++ str

Problem

`take (-1) []` is `[]`. What are the reasons to prefer this over a partial function, that is, an error? Are there use cases where this property is exploited?

Original source