A partial function is a function that is not defined for all possible arguments of the specified type. Examples in the Haskell standard library are:
- ,head: undefined for empty liststail
- : undefined if the index is at least as big as the list length(!!)
- : undefined if the divisor is zerodiv
The opposite is a total function. You should strive to avoid partial functions and instead write total ones. This makes it much easier to reason about your code and makes "if your code compiles, it probably works" true for your code more often.
Usually if you have a partial function, it's because your types are incorrect and you should fix your types rather than writing partial functions which guarantee the impossible.A good example of this is
You almost never have an excuse for writing a partial function!
There are methods to avoid the use of partial functions.