Slide 1

Slide 1 text

CHEAT-SHEET Folding #3 ∢ / \ π’‚πŸŽ ∢ / \ π’‚πŸ ∢ / \ π’‚πŸ ∢ / \ π’‚πŸ‘ 𝒇 / \ π’‚πŸŽ 𝒇 / \ π’‚πŸ 𝒇 / \ π’‚πŸ 𝒇 / \ π’‚πŸ‘ 𝒆 @philip_schwarz slides by https://fpilluminated.com/

Slide 2

Slide 2 text

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 π‘“π‘œπ‘™π‘‘ :: 𝛼 β†’ 𝛽 β†’ 𝛽 β†’ 𝛽 β†’ 𝛼 β†’ 𝛽 π‘“π‘œπ‘™π‘‘ 𝑓 𝑣 = 𝑣 π‘“π‘œπ‘™π‘‘ 𝑓 𝑣 π‘₯ ∢ π‘₯𝑠 = 𝑓 π‘₯ π‘“π‘œπ‘™π‘‘ 𝑓 𝑣 π‘₯𝑠

Slide 3

Slide 3 text

𝑔 = 𝑣 𝑔 π‘₯ ∢ π‘₯𝑠 = 𝑓 π‘₯ 𝑔 π‘₯𝑠 π‘ π‘’π‘š ∷ 𝐼𝑛𝑑 β†’ 𝐼𝑛𝑑 π‘ π‘’π‘š = 0 π‘ π‘’π‘š π‘₯ ∢ π‘₯𝑠 = π‘₯ + π‘ π‘’π‘š π‘₯𝑠 π‘ π‘’π‘š = π‘“π‘œπ‘™π‘‘ + 0 ⟺ 𝑔 = π‘“π‘œπ‘™π‘‘ 𝑓 𝑣 ⟺ π‘π‘Ÿπ‘œπ‘‘π‘’π‘π‘‘ ∷ 𝐼𝑛𝑑 β†’ 𝐼𝑛𝑑 π‘π‘Ÿπ‘œπ‘‘π‘’π‘π‘‘ = 1 π‘π‘Ÿπ‘œπ‘‘π‘’π‘π‘‘ π‘₯ ∢ π‘₯𝑠 = π‘₯ Γ— π‘π‘Ÿπ‘œπ‘‘π‘’π‘π‘‘ π‘₯𝑠 π‘π‘Ÿπ‘œπ‘‘π‘’π‘π‘‘ = π‘“π‘œπ‘™π‘‘ (Γ—) 1 ⟺ π‘™π‘’π‘›π‘”π‘‘β„Ž ∷ [Ξ±] β†’ 𝐼𝑛𝑑 π‘™π‘’π‘›π‘”π‘‘β„Ž [ ] = 0 π‘™π‘’π‘›π‘”π‘‘β„Ž π‘₯ ∢ π‘₯𝑠 = 1 + π‘™π‘’π‘›π‘”π‘‘β„Ž π‘₯𝑠 π‘™π‘’π‘›π‘”π‘‘β„Ž = π‘“π‘œπ‘™π‘‘ (πœ†π‘₯. πœ†π‘›. 1 + 𝑛) 0 ⟺ (β§Ί) ∷ [Ξ±] β†’ [Ξ±] β†’ [Ξ±] β§Ί 𝑦𝑠 = 𝑦𝑠 π‘₯ ∢ π‘₯𝑠 β§Ί 𝑦𝑠 = π‘₯ ∢ (π‘₯𝑠 β§Ί 𝑦𝑠) (β§Ί 𝑦𝑠) = π‘“π‘œπ‘™π‘‘ ∢ 𝑦𝑠 ⟺ concat ∷ [ Ξ± ] β†’ [Ξ±] concat = concat π‘₯𝑠 ∢ π‘₯𝑠𝑠 = π‘₯𝑠 β§Ί π‘π‘œπ‘›π‘π‘Žπ‘‘ π‘₯𝑠𝑠 ⟺ concat = π‘“π‘œπ‘™π‘‘ (β§Ί) [ ]

Slide 4

Slide 4 text

The Triad of π‘šπ‘Žπ‘, π‘“π‘–π‘™π‘‘π‘’π‘Ÿ and π‘“π‘œπ‘™π‘‘ π‘šπ‘Žπ‘ Ξ» The π‘π‘Ÿπ‘’π‘Žπ‘‘, π‘π‘’π‘‘π‘‘π‘’π‘Ÿ, and π‘—π‘Žπ‘š of Functional Programming =

Slide 5

Slide 5 text

𝑔 = 𝑣 𝑔 π‘₯ ∢ π‘₯𝑠 = 𝑓 π‘₯ 𝑔 π‘₯𝑠 π‘šπ‘Žπ‘ ∷ 𝛼 β†’ 𝛽 β†’ 𝛼 β†’ 𝛽 π‘šπ‘Žπ‘ 𝑓 = π‘šπ‘Žπ‘ 𝑓 π‘₯ ∢ π‘₯𝑠 = 𝑓 π‘₯ ∢ π‘šπ‘Žπ‘ 𝑓 π‘₯𝑠 π‘šπ‘Žπ‘ 𝑓 = π‘“π‘œπ‘™π‘‘π‘Ÿ πœ†π‘₯. πœ†π‘₯𝑠. 𝑓 π‘₯ ∢ π‘₯𝑠 [ ] ⟺ π‘“π‘–π‘™π‘‘π‘’π‘Ÿ ∷ (𝛼 β†’ π΅π‘œπ‘œπ‘™) β†’ 𝛼 β†’ π‘Ž π‘“π‘–π‘™π‘‘π‘’π‘Ÿ p = π‘“π‘–π‘™π‘‘π‘’π‘Ÿ p π‘₯ ∢ π‘₯𝑠 = 𝐒𝐟 𝑝 π‘₯ 𝐭𝐑𝐞𝐧 π‘₯ ∢ π‘“π‘–π‘™π‘‘π‘’π‘Ÿ p π‘₯𝑠 𝐞π₯𝐬𝐞 π‘“π‘–π‘™π‘‘π‘’π‘Ÿ p π‘₯𝑠 π‘“π‘–π‘™π‘‘π‘’π‘Ÿ p = π‘“π‘œπ‘™π‘‘π‘Ÿ (πœ†π‘₯. πœ†π‘₯𝑠. 𝐒𝐟 𝑝 π‘₯ 𝐭𝐑𝐞𝐧 π‘₯ ∢ π‘₯𝑠 𝐞π₯𝐬𝐞 π‘₯𝑠) [ ] ⟺ 𝑔 = π‘“π‘œπ‘™π‘‘π‘Ÿ 𝑓 𝑣 ⟺ π‘šπ‘Žπ‘ Ξ» π‘“π‘œπ‘™π‘‘ =

Slide 6

Slide 6 text

https://fpilluminated.com/ inspired by