divTenBy :: Double -> Double
divTenBy n = 10 / n
If you actually call the above function you get a runtime exception. We really don't like functions that do this; they are called partial. divTenBy :: Double -> Double
divTenBy n = 10 / n
If you actually call the above function you get a runtime exception. We really don't like functions that do this; they are called partial. $ python3
Python 3.9.1 (default, Feb 3 2021, 07:04:15)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 10 / 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
>>>It's "partial" because it's not defined for 0.
That would be the "right way" to fix this.
(or create a type NotNilDouble, lol)
It's clearer for partial function "head :: [a] -> a", which takes the first of a list if it exists, and explodes without dignity if the list is empty (this is what makes head partial).
A proposal is "head :: [a] -> Maybe a", so head returns Nothing when the list is empty.
https://www.idris-lang.org/docs/current/prelude_doc/docs/Pre...'
https://www.idris-lang.org/docs/current/contrib_doc/docs/Dat...
f :: Int -> Bool
f 0 = True
f 1 = False
f n = f (n + 1)
is surjective onto Bool but also partial (doesn't return for n > 1). In Haskell we say that when a function doesn't return, the output is bottom, written as ⊥.
You could say that a function f : A -> B is partial if f^{-1}(B \ ⊥) is surjective.