Slides for the fifth lesson in my PureScript lunch-n-learn series. This lesson concludes "Recursion, Maps, & Folds," chapter 4 of "PureScript by Example," covering folds.
numbers [a, b, c] such that a² + b² = c². Write a function triples that takes an Integer and uses the guard function to calculate and return all Pythagorean triples whose components are less than n.
the left”. :type ▪ forall a b f. (Foldable f) => (b -> a -> b) -> b -> f a -> b ◦ foldr “folds from the right”. :type ▪ forall a b f. (Foldable f) => (a -> b -> b) -> b -> f a -> b Data.Foldable
Few JS engines perform proper “tail call optimization” • The PureScript compiler will compile recursive functions in “tail call” position to simple while loops • More complete solutions can be found in the purescript- free and purescript-tailrec packages Tail Recursion
Few JS engines perform proper “tail call optimization” • The PureScript compiler will compile recursive functions in “tail call” position to simple while loops • More complete solutions can be found in the purescript- free and purescript-tailrec packages Tail Recursion
Few JS engines perform proper “tail call optimization” • The PureScript compiler will compile recursive functions in “tail call” position to simple while loops • More complete solutions can be found in the purescript- free and purescript-tailrec packages Tail Recursion
Few JS engines perform proper “tail call optimization” • The PureScript compiler will compile recursive functions in “tail call” position to simple while loops • More complete solutions can be found in the purescript- free and purescript-tailrec packages Tail Recursion
-- the head of the input array to the end of the result. -- NOT tail-recursive! reverse :: forall a. Array a -> Array a reverse [] = [] reverse xs = snoc (reverse (unsafePartial tail xs)) (unsafePartial head xs)