Functional Programming in C++

Hi all,

My name is Alexander Granin. I'm collecting materials about Functional Programming in C++: articles, talks, libraries.

https://github.com/graninas/cpp_functional_programming

I'm a Haskeller and C++ developer who brings the ideas of Functional Programming into the C++ world. Currently, I'm preparing my next (keynote) talk for C++ Siberia 2019: "The Present and The Future of Functional Programming in C++". I'm looking for amazing samples and approaches to be overviewed in my talk. In particular, I'm interested in monads implementation approaches, and also in do-notation implementation attempts. I'm asking to help me to find more insights, thanks! :)

36 comments · 82% upvoted · other discussions

comments

bandzaw

The recently released book Functional Programming in C++ by Ivan Čukić (/u/ivan-cukic) is really really good, check it out!

https://www.manning.com/books/functional-programming-in-c-plus-plus

graninas [OP]

Well, I have it already. I was talking with Ivan about the book and hope to talk more at C++ Siberia 2019.

(I also was a reviewer of the book proposal for Manning and suggested to rework the table of contents in order to make it more consistent. Not sure how many of my suggestions have been taken by Ivan, but I like to think there is my little contribution to it. But of course, Ivan made a great work, so we can now enjoy his book)

ivan-cukic

Thanks for this comment /u/bandzaw :)

/u/graninas was one of the book proposal reviewers. Sadly, I didn't know that for a long time - all reviewers in Manning are anonymous - the manuscript reviewers have been automatically added by Manning to the acknowledgements section. Unfortunately, it seems they didn't include the people who gave suggestions to improving the book ToC. :/

graninas [OP]

Hi Ivan,

That's OK. :) The book is wonderful anyway.

​

sajid_farooq

Just wanted to chime in to agree: the book is wonderful.

Sulatra

This was a very good course on introducing FP via c++. Not sure if it has exactly what you are looking for, though ^^"

graninas [OP]

Thank you. I probably need to add one more section for courses into the document.

Betadel

Check out this talk by Simon Brand and Phil Nash: https://youtu.be/GC4cp4U2f2E

They talk about monadic error handling.

graninas [OP]

That's cool that so famous people are arguing about FP. Thank you!

ricejasonf

Boost.Hana is a library with concepts borrowed from category theory as you see in Haskell: http://boostorg.github.io/hana/group__group-concepts.html Also here is a video demonstrating making a promise monad with it for full duplex messaging: https://youtu.be/UalTAQmP3iE?t=1348

dodheim

While the latter is C++03, Boost.Hana and Boost.Phoenix are both highly relevant.

ricejasonf

No, that is definitely C++17

dodheim

The latter of "Boost.Hana and Boost.Phoenix". ;-]

graninas [OP]

In some sense, Boost.Spirit is functional too, but you know, it's ugly.

SplinterOfChaos

Probably obsolete by now, but I used to blog about writing Haskell in c++ over at http://yapb-soc.blogspot.com/?m=1

graninas [OP]

http://yapb-soc.blogspot.com/?m=1

Hi, that's a great work done. I'll add references to your posts into the document.

May I ask is there a chance you'll write more posts about the upcoming FP fetures?

germandiago

Hello. I did a talk about functional-style pogramming some time back in the Ho Chi Minh City C++ users group.

It is not a pure functional programming talk purely speaking but related, so just in case you want to take a look:

https://www.slideshare.net/GermnDiagoGmez/functional-style-programming?qid=bb32347f-bb9e-4eb4-b0fd-de5d8f9a0b11&v=&b=&from_search=2

graninas [OP]

Hi, that's cool, thanks, I'll check it out.

I think we need one more section for slides without videos in the document.

Sanae_

https://www.fluentcpp.com/ is blog with strong functional influences, although it's not organized as a complete, comprehensive set of best-practices.

graninas [OP]

Yes, true, thanks.

Jonathan Boccara does a great job popularising the ideas from the functional world (but not only). I'll add his materials into the list.

kernelgauss

this talk impressed me a lot considering I wasn't expecting it to be so functional (maybe why it's not on your list). They build a regex parser that is completely constexpr (no runtime) using lambdas https://www.youtube.com/watch?v=PJwd4JLYJJY

graninas [OP]

Interesting stuff, thanks!

I'll be building a monadic parsers library for myself soon (resembling the Parsec library from Haskell), so that talk is pretty much in-time.

tvaneerd

Look for stuff from Juan Pedro Bolivar Puente, such as https://www.youtube.com/watch?v=sPhpelUfu8Q

graninas [OP]

His talks are very good, thanks!

autoluto

Not really into functional programming myself, but I've heard good things about this:

https://github.com/beark/ftl

graninas [OP]

Indeed, thanks. I've included this library into the document already. Also, it was a source of inspiration for my own research of FP in C++.

TobyAllsopp

You might be interested in my attempts to (ab)use coroutines to approximate do-notation here: https://github.com/toby-allsopp/coroutine_monad

graninas [OP]

Thank you, I'm definitely interested in the approach you're researching. I was wondering if coroutines have something to do with monads, and it seems they have. Unfortunately, without a real do-notation, we'll be dealing with limited half-decisions.

tvaneerd
graninas [OP]

Wonderful talks, thank you!

sutambe
graninas [OP]

Great stuff, thank you!

TotesMessenger

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

 If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)

pstomi

You should check out FunctionalPlus; it has a quite good API https://github.com/Dobiasd/FunctionalPlus/blob/master/README.md

It also provides an API search site à la Hoogle http://www.editgym.com/fplus-api-search/

The author also hosts a very interesting course on functional programming in C++ on Udemy

graninas [OP]

Very nice indeed, thanks!

lion_137