The answers explain all, I will just add one example in each language:
def add(x,y):
return x+y
f = add(1)
print(f(3))
f = add(1)
TypeError: add() missing 1 required positional argument: 'y'
this is neither a partial function nor a curried function, this is only a function that you didn't gave all its arguments.
A curried function in python should be like this:
partialAdd= lambda x: lambda y: x + y
plusOne = partialAdd(1)
print(plusOne(3))
4
and in haskell:
plus :: Int -> Int -> Int
plus x y = x + y
plusOne = plus 1
plusOne 4
5
A partial function in python:
def first(ls):
return ls[0]
print(first([2,4,5]))
print(first([]))
output
2
print(first([]))
File "main.py", line 2, in first
return ls[0]
IndexError: list index out of range
And in Haskell, as your link showed up:
head [1,2,3]
3
head []
*** Exception: Prelude.head: empty list
So what is a total function?
Well, basically the opposite: this is a function that will work for any input of that type. Here is an example in python:
def addElem(xs, x):
xs.append(x)
return xs
and this works even for infinite lists, if you use a little trick:
def infiniList():
count = 0
ls = []
while True:
yield ls
count += 1
ls.append(count)
ls = infiniList()
for i in range(5):
rs = next(ls)
print(rs, addElem(rs,5))
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
And the equivalent in Haskell:
addElem :: a -> [a] -> [a]
addElem x xs = x : xs
addElem 3 (take 10 [1..])
=> [3,1,2,3,4,5,6,7,8,9,10]
Here the functions don't hang forever. The concept is the same: for every list the function will work.
partial
performs partial application, whereas Haskell does that automatically. The wiki entry refers to partial functions, which is a term from mathematics. – Segregationistadd 3 5
isn't a single function application. This first appliesadd
to 3 to get a new function, which is then applied to 5. – Decarbonizepartial
method is a forward declaration of an optionally implemented private method elsewhere in the project codebase. – Fadilnew_function = functools.partial(add, 1)
– AntiquatedTraceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: add() missing 1 required positional argument: 'y'
– Highmuckamuck