4 ms·
God no. If your loop isn't a map, it's almost certainly a fold. If you free up your syntax to make them easier to produce then they show up everywhere. Sum is a
by tel 13y ago
God no. If your loop isn't a map, it's almost certainly a fold. If you free up your syntax to make them easier to produce then they show up everywhere. Sum is a menial example.
- kazagistar 13y agoWhy not use a loop instead though?
- pestaa 13y agoBecause you need to track and update the temporary state. Maps and folds let you define your stepping algorithm separately.
- kazagistar 13y agoIn python? I wasn't aware that fold did anything other then iterate in order...
- calpaterson 13y ago> If your loop isn't a map, it's almost certainly a fold. ...all loops can be represented as folds
- tel 13y agoNot strictly true, but all maps can be represented as a fold. That's not usually the best tool though.
- tel 13y agoTo clarify this now that I'm not on my phone, folds may not express termination by themselves, they depend upon the type that they're folding up. More formally, folds are catamorphisms which operate on data, but you often need to use codata to generate the structures to fold over.