Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I'm not sure I understand the relationship between partial function and exception handling. Aren't partial functions just curried?

You're thinking "partially applied function", which uses very similar terms but means something completely unrelated.

A partially applied function is a function which is applied to a subset of its formal arguments, yielding a function taking the leftover arguments.

A partial function is contrasted with a total function and the term is about the relation between inputs and outputs, namely does every possible input value yield an output. The example of `first` used in the essay is pretty common because it's quite clear: given `first :: [a] -> a`, what happens if you call `first` with an empty list? Well it can't succeed, it can't just give you an `a` out of nowhere because it doesn't have anything to do that. So despite an empty array being a possible input value, there is no output for it: it is a partial function, it only partially maps its inputs to its outputs.

`first :: [a] -> Maybe a` would be total: in the case of an empty input it returns `None`, otherwise it returns `Some a`.



Ah thanks, I'm used to this being called a "complete function".


`Just a` / `Nothing` in case of Haskell :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: