Arbitrary Information
When we have an arbitrary amount of information - in other words, we don’t know the constraints on the information size (for example, asking about favorite Quidditch teams) - we must use arbitrary sized data. This occurs when we don’t know ahead of time how many instances or options there will be.
When we have arbitrary-sized data requirements, we want to include self references in our type comments. For example:
;; ListOfString is one of:
;; - empty
;; - (cons String ListOfString)The trick to ensure that we used well-formed data definitions; that is to say, that the self-referential definition has a base case that will avoid having an infinite loop. The structure of a well formed self-reference is as follows:
;; Well formed self-reference:
;; - at least one base case
;; - at least one self-reference caseWhen creating examples and tests, ensure that they include both the base and self-reference cases. The structure of these self-referential functions can be summarised with the following truth table:
Transclude of Self-Reference-List#truth-table-for-arbitrary-information-function
References
- How to code: Simple data. edX. Retrieved January 22, 2022 from https://www.edx.org/course/how-to-code-simple-data