Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Haskell: Total and Partial functions

If a Function is well defined on all possible arguments, then it is called total function, if it is not well defined for all possible arguments, then it is called partial function. There are several partial functions defined in Haskell standard library.

For Example,
    a. head, tail: undefined for empty lists
    b. (!!) : undefined if the index is at least as big as the list length

    c. div : undefined if the divisor is zero

Prelude> head []
*** Exception: Prelude.head: empty list
Prelude>
Prelude> tail []
*** Exception: Prelude.tail: empty list
Prelude>
Prelude> 10 `div` 0
*** Exception: divide by zero

Always avoid of defining partial functions in your code.

Following post explains some guide lines to avoid partial functions.
https://wiki.haskell.org/Avoiding_partial_functions




Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Haskell: Total and Partial functions

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×