Skip to content

Latest commit

 

History

History
24 lines (21 loc) · 885 Bytes

where_can_we_introduce_partiality_in_functions.org

File metadata and controls

24 lines (21 loc) · 885 Bytes

Where can we introduce partiality in functions

Note

A function that is not total, is partial. Yet again pertaining to Haskell, but is valid for other FP languages.

Where partiality can be introduced:

  • Non-exhaustive pattern matching
  • Missing conditions in guards
  • Any pattern matching, basically
  • Unspecified fields of records / structs / etc.
  • Using bottom, e.g. error and undefined in Haskell
  • Non-terminating loops
  • Seg faults, and other low-level issues

Be careful when using wildcards, as adding new cases to types will lead to unexpected behaviour - prefer matching on all cases of a type instead when pattern matching. Same goes when using error for seemingly unreachable code, or “trusting” that functions from libraries are total.

Links

z:/totality_in_functional_programming?type=branch