Functional programming approaches to code design

The Motoko language sometimes takes a functional approach, as can be seen when making ’changes’ to immutable arrays
https://sdk.dfinity.org/language-guide/index.html#immutable-arrays
and when appending to lists
https://sdk.dfinity.org/language-guide/index.html#stdlib-list

As a useful guide, Joachim Breitner’s Haskell series may be worth a review to get you thinking about functional programming when approaching your Motoko projects.

Joachim Breitner’s Haskell for Readers, includes a good primer on functional programming:
http://haskell-for-readers.nomeata.de/
And his blog entry on this:
http://www.joachim-breitner.de/blog/750-Teaching_to_read_Haskell

Joachim’s CIS 194 Haskell course at the University of Pennsylvania also contains a good overview of these concepts:
http://cis.upenn.edu/~cis194/fall16/

11 Likes

If and when you ever want to dive further into the technical design of functional data structures and algorithms, including complexity analysis of eager and lazy ones, I highly recommend Ravi Chugh’s lecture notes and example programs (all based on Elm, which is similar-ish to Motoko in broad ways):

https://www.classes.cs.uchicago.edu/archive/2019/spring/22300-1/schedule.html

That page gives the topic list, with links to example code and lecture notes.

7 Likes

That’s a great resource, thanks Matthew!

3 Likes