Hacker School

Recurse Center

"recurse"?

What the heck

does that mean?

recursive function:

a procedure or subroutine, implemented in a programming language, whose implementation references itself

recurse:

what a recursive function does

Can we describe Recurse Center with a recursive function?

Probably not!

But let's do it anyway!

attendRC :: Person -> Time -> Person
attendRC :: Person -> Time -> Person

attendRC p t = attendRC (exp p) (t - 1)

 

-- Have awesome experiences

exp :: Person -> Person

attendRC :: Person ->
            [ Person -> Person ]
            Time -> 
            Person
attendRC p fs t = attendRC 
                  (foldr ($) p fs ) 
                  fs
                  (t - 1)
dayAtRC :: Person -> Person
dayAtRC libby = foldr ($) libby 

                                    [ drinkCoffee,

                                      codeGame,

                                      eatPadThai,

                                      pairWithNikki ]

How does the recursion end?

attendRC :: Person ->
            [ Person -> Person ]
            Time -> 
            Person
attendRC p _ 0  = neverGraduate p
attendRC p fs t = attendRC 
                  (foldr ($) p fs ) 
                  fs
                  (t - 1)

This compiles!!

type Person = ()
type Time = Int

neverGraduate :: Person -> Person
neverGraduate p = undefined

attendRC :: Person ->
            [ Person -> Person ]
            Time -> 
            Person
attendRC p _ 0  = neverGraduate p
attendRC p fs t = attendRC 
                  (foldr ($) p fs ) 
                  fs
                  (t - 1)

Limitations?

$$$

Made with Slides.com