5 ms·
Partial functions are not the same thing as "partially applied functions". Partial functions means that not every element of the domain is mapped to an element
by samthecoy 6y ago
Partial functions are not the same thing as "partially applied functions". Partial functions means that not every element of the domain is mapped to an element of the range, for example:
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.
- a_wild_dandan 6y agoAh, so partial functions aren't onto (i.e. surjective).
- deleted 6y ago[deleted]
- curtisf 6y agoNo, they are not functions in the mathematical sense. It's not that they don't cover the output space, they don't cover the input space.
- wetmore 6y agoNot exactly, partial functions can be surjective, eg 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.
- deleted 6y ago[deleted]
- Athas 6y agoAm I missing something subtle? Why would you get a runtime exception if you call this function?
- jsmith45 6y agoThe parent missed a part. If you call it with 0 you get an exception, because division by zero obviously.
- yakubin 6y agoNo, you don't. You get Infinity. That's how floating point works.
- smabie 6y agoIn most languages you get an exception
- yakubin 6y agoWhich languages would those be?
- smabie 6y agoI guess I'm thinking of Python mostly. I thought OCaml did as well but apparently not.
- warkdarrior 6y ago$ 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 >>>
- yakubin 6y agoAlthough Python seems to be the exception to the rule here, your example isn't exactly right. In your example, you're performing integer division, not floating point division. In most languages, integer division by zero is indeed some kind of exception (or UB, which will most likely result in a hardware exception, causing a signal sent to the process). However, floating point division by zero is well-defined, as per definition of floating point arithmetic (in some RFCs), and most languages don't throw exceptions in this case. Python indeed seems to be the exception to the rule.