Hello, friends.
I'm starting to "formally" dive into functional programming. I was hoping to use Julia for this (instead of something like Haskell). Any suggestions of books/articles/blog posts/packages? I've found MLStyle.jl , but I don't have the proper knowledge yet to understand most of the functional programming idiom. I'd love some guidance from the pros :)
P.S: My main motivation is to learn how to better design some packages I'm working on.
"Functional programming" can mean different things. It can mean no side-effects/referential transparency, or a paradigm of programming that uses map/filter/reduce, or both.
Which in particular are you interested in?
For the latter, Julia has versions of map/filter/reduce builtin to the language, so you really don't need a library. MLStyle.jl pattern matching is not really inherent to functional programming, but is common in some FP languages. You might like Folds.jl and the libraries built on top of it, as well as this JuliaCon 2022 talk: https://live.juliacon.org/talk/WKNY78 for getting started.
Thanks @Michael Fiano . The term Functional Programming seem to be quite overloaded. That's actually one of the problems I'm facing and trying to understand.
Welcome to CS, where even the term overload
is overloaded :smile:
@Michael Fiano , I really liked the talk... Do you have any references you suggest for map/filter/ reduce
part of FP?
As I said, my main interest is in improving my code design. As I've started coding more complex packages, I realized that I needed a better understanding of the subject.
Hmm, you could check out the API for map
, reduce
, foldl
, foldr
, and filter
perhaps.
reduce
, and by extension foldl
and foldr
can take some getting used to, but the other two are pretty powerful on their own and pretty easy to grasp.
The thing about FP is it favors higher order functions. Julia was designed with this in mind, but Julia is multi-paradigm, and doesn't constrain your design if you need to reach for a comprehension or for loop or such.
I mean, truth is that I understand what they do, but I don't understand why it would be better than what one conventionally uses.
It is more composable. Instead of looping over something, you can for example pass a re-usable function to apply to all elements of a container, with the higher order function map
.
map(isodd, 1:10)
for example will tell you which elements are odd. You are not restricted to using builtin functions like isodd
though. You can design re-usable functions that are used to map over or filter collections.
For anything that conforms to the iterate interface.
For that sort of thing I’d heartily recommend Transducers.jl over the regular map, filter, fold constructions
The way to think about them is that they’re a more structured form of a loop, and because they have more structure, they can be (ideally) understood better by a compiler
Thanks, @Mason Protter . I'll take a look.
At the moment, I'm reading "Grokking Simplicity" on function programming. Have you guys read it?
I'd love to hear book references, even if they are academic. I don't mind studying a bit of CS.
What opened my eyes to handling state inside a program in a functional way was https://prog21.dadgum.com/23.html. Part 3 in particular talks about how (not) to pass state through the system.
Last updated: Nov 22 2024 at 04:41 UTC