Most of the programming you have done so far has been in the
functional style. Although this has enabled you to write succinct, powerful
programs, you never quite used the functional style to its full potential.
Functional programming means more than just treating functions as values.
Embracing the functional programming paradigm and having it help shape your
thought process will enable you to write programs that would otherwise be
prohibitively difficult in an imperative style.
In this chapter, we build on what you learned about functional
programming back in Chapter3, and introduce
new language features that help you to be more productive in the functional
style. For example, using active patterns allows you to increase the power
of your pattern matching and eliminate the need for when guards, and by creating auto-opened modules,
you can extend common F# modules.
In addition, we look at some of the more mind-bending aspects of
functional programming. You will learn how to use advanced forms of
recursion to avoid stack overflows and write more efficient programs using
lists. We also take a look at some common design patterns and data
structures for functional code.
I close my eyes and imagine myself making this shot. Woomp, woomp, woomp. Stop, aim, and shoot. Clang. Off the rim. And I missed. Again.
“That’s P.” Linc gets the rebound.
“Which one?” I ask.
“Third.” He stands over next to my mom’s rosebushes, dribbles twice, and shoots. Swish. He looks at me, shrugs, and goes to get the ball.
It stopped raining during the walk home from school. But, thanks to layers of stratocumulus clouds, there’s no sun and, since it’s November, it’s kind of cold. But North Carolina cold, so an extra sweatshirt means it’s still a good day for basketball.
I kick at the jagged crack at the spot where the driveway bends toward the garage on the side of our house. “So what do you think about no grades from Sister Stevie?”
“I think it’s great. You know I don’t belong in that class with you brains. This way not everybody has to know.” Linc bounces the ball to me. “But I’m not telling my parents until I have to.”
Woomp, woomp, woomp. Stop, aim, and shoot. Silence. That’s the sound of my shot missing the net, the rim, and the backboard. Then, plop, crunch. That’s the sound of the ball landing in a puddle and then in my mom’s flowers. Pansies, I think. I don’t know why she keeps planting flowers behind the hoop. They always end up flat or dead. And she always plants more.