Yes. Two important points to consider: seq evaluates WHNF (normal form with a weak head), and secondData is a list. WHNF means that the data will be calculated in the external constructor itself, and the most external constructor for secondData is : (if it is not empty, then the constructor [] ). So
secondData `seq` generateBars (barSize featureSet) secondData
will only do enough work to determine if secondData an empty list or has at least one element.
length evaluates the spine of the list, which basically means that it determines how many items are in the list, going through the full structure. This means that length will work more than seq for lists with more than 1 element.
You can use deepseq (from deepseq ) to fully evaluate the list, but you may not need it. length and deepseq should completely traverse the list. If you do not need to know this information in advance, it will be wasted, as your consumer will also have to sort through the list. Depending on the consumer, this can also increase the storage space of the heap, because deepseq will force all the data structures to be created at first, but they will not be GC'd until the algorithm is complete.
source share