Share
Embed
Transcript
6 slides
-
CHEAT-SHEET Folding #3 โถ / \ ๐๐ โถ / \
๐๐ โถ / \ ๐๐ โถ / \ ๐๐ ๐ / \ ๐๐ ๐ / \ ๐๐ ๐ / \ ๐๐ ๐ / \ ๐๐ ๐ @philip_schwarz slides by https://fpilluminated.com/ -
The universal property of ๐๐๐๐ ... For finite lists, the
universal property of ๐๐๐๐ can be stated as the following equivalence between two definitions for a function ๐ that processes lists: ๐ = ๐ โบ ๐ = ๐๐๐๐ ๐ ๐ ๐ ๐ฅ โถ ๐ฅ๐ = ๐ ๐ฅ ๐ ๐ฅ๐ In the right-to-left direction, substituting ๐ = ๐๐๐๐ ๐ ๐ into the two equations for ๐ gives the recursive definition for ๐๐๐๐ . Conversely, in the left-to-right direction the two equations for g are precisely the assumptions required to show that ๐ = ๐๐๐๐ ๐ ๐ using a simple proof by induction on finite listsโฆ Taken as a whole, the universal property states that for finite lists the function ๐๐๐๐ ๐ ๐ is not just a solution to its defining equations, but in fact the unique solutionโฆ. The universal property of ๐๐๐๐ can be generalised to handle partial and infinite listsโฆ Graham Hutton @haskelhutt ๐๐๐๐ :: ๐ผ โ ๐ฝ โ ๐ฝ โ ๐ฝ โ ๐ผ โ ๐ฝ ๐๐๐๐ ๐ ๐ฃ = ๐ฃ ๐๐๐๐ ๐ ๐ฃ ๐ฅ โถ ๐ฅ๐ = ๐ ๐ฅ ๐๐๐๐ ๐ ๐ฃ ๐ฅ๐ -
๐ = ๐ฃ ๐ ๐ฅ โถ ๐ฅ๐ = ๐ ๐ฅ
๐ ๐ฅ๐ ๐ ๐ข๐ โท ๐ผ๐๐ก โ ๐ผ๐๐ก ๐ ๐ข๐ = 0 ๐ ๐ข๐ ๐ฅ โถ ๐ฅ๐ = ๐ฅ + ๐ ๐ข๐ ๐ฅ๐ ๐ ๐ข๐ = ๐๐๐๐ + 0 โบ ๐ = ๐๐๐๐ ๐ ๐ฃ โบ ๐๐๐๐๐ข๐๐ก โท ๐ผ๐๐ก โ ๐ผ๐๐ก ๐๐๐๐๐ข๐๐ก = 1 ๐๐๐๐๐ข๐๐ก ๐ฅ โถ ๐ฅ๐ = ๐ฅ ร ๐๐๐๐๐ข๐๐ก ๐ฅ๐ ๐๐๐๐๐ข๐๐ก = ๐๐๐๐ (ร) 1 โบ ๐๐๐๐๐กโ โท [ฮฑ] โ ๐ผ๐๐ก ๐๐๐๐๐กโ [ ] = 0 ๐๐๐๐๐กโ ๐ฅ โถ ๐ฅ๐ = 1 + ๐๐๐๐๐กโ ๐ฅ๐ ๐๐๐๐๐กโ = ๐๐๐๐ (๐๐ฅ. ๐๐. 1 + ๐) 0 โบ (โงบ) โท [ฮฑ] โ [ฮฑ] โ [ฮฑ] โงบ ๐ฆ๐ = ๐ฆ๐ ๐ฅ โถ ๐ฅ๐ โงบ ๐ฆ๐ = ๐ฅ โถ (๐ฅ๐ โงบ ๐ฆ๐ ) (โงบ ๐ฆ๐ ) = ๐๐๐๐ โถ ๐ฆ๐ โบ concat โท [ ฮฑ ] โ [ฮฑ] concat = concat ๐ฅ๐ โถ ๐ฅ๐ ๐ = ๐ฅ๐ โงบ ๐๐๐๐๐๐ก ๐ฅ๐ ๐ โบ concat = ๐๐๐๐ (โงบ) [ ] -
The Triad of ๐๐๐, ๐๐๐๐ก๐๐ and ๐๐๐๐ ๐๐๐ ฮป The
๐๐๐๐๐, ๐๐ข๐ก๐ก๐๐, and ๐๐๐ of Functional Programming = -
๐ = ๐ฃ ๐ ๐ฅ โถ ๐ฅ๐ = ๐ ๐ฅ
๐ ๐ฅ๐ ๐๐๐ โท ๐ผ โ ๐ฝ โ ๐ผ โ ๐ฝ ๐๐๐ ๐ = ๐๐๐ ๐ ๐ฅ โถ ๐ฅ๐ = ๐ ๐ฅ โถ ๐๐๐ ๐ ๐ฅ๐ ๐๐๐ ๐ = ๐๐๐๐๐ ๐๐ฅ. ๐๐ฅ๐ . ๐ ๐ฅ โถ ๐ฅ๐ [ ] โบ ๐๐๐๐ก๐๐ โท (๐ผ โ ๐ต๐๐๐) โ ๐ผ โ ๐ ๐๐๐๐ก๐๐ p = ๐๐๐๐ก๐๐ p ๐ฅ โถ ๐ฅ๐ = ๐ข๐ ๐ ๐ฅ ๐ญ๐ก๐๐ง ๐ฅ โถ ๐๐๐๐ก๐๐ p ๐ฅ๐ ๐๐ฅ๐ฌ๐ ๐๐๐๐ก๐๐ p ๐ฅ๐ ๐๐๐๐ก๐๐ p = ๐๐๐๐๐ (๐๐ฅ. ๐๐ฅ๐ . ๐ข๐ ๐ ๐ฅ ๐ญ๐ก๐๐ง ๐ฅ โถ ๐ฅ๐ ๐๐ฅ๐ฌ๐ ๐ฅ๐ ) [ ] โบ ๐ = ๐๐๐๐๐ ๐ ๐ฃ โบ ๐๐๐ ฮป ๐๐๐๐ =