top | item 26078503

(no title)

samthecoy | 5 years 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.

discuss

order

Athas|5 years ago

Am I missing something subtle? Why would you get a runtime exception if you call this function?

jsmith45|5 years ago

The parent missed a part. If you call it with 0 you get an exception, because division by zero obviously.

the_af|5 years ago

If you call it with argument 0 you get a runtime exception, because it results in a division by zero.

It's "partial" because it's not defined for 0.

a_wild_dandan|5 years ago

Ah, so partial functions aren't onto (i.e. surjective).

wetmore|5 years ago

Not 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.

curtisf|5 years ago

No, 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.