python icon indicating copy to clipboard operation
python copied to clipboard

[New Exercise Idea]: Maybe functor

Open samfrances opened this issue 3 years ago • 5 comments

I don't know if this is too much Functional Programming for Python, but I wonder if a basic exercise to construct a Maybe functor (not monad) would be a welcome addition? I would be happy to have a go at writing this.

samfrances avatar Sep 15 '21 18:09 samfrances

HI @samfrances 👋🏽

I did have to google Maybe functor 😊 😉
But I don't think a Maybe functor would be "too much" functional programming for Python! 😄 And I'd love you to "have a go".

Would this be a practice exercise, or a concept exercise?

If it is a concept exercise, we'll probably want to discuss it in a bit more detail, and I might want to enlist your help thinking through the chunking and progression of our "functional" exercises and the prerequisites.

Right now, we have really big chunks: functions, higher-order functions, anonymous-functions, functional tools, functools, iterators, and itertools. Which is not optimal. We'd probably want to break those down and take care to map functional language and techniques (functor, monad, composed functions, applicatives etc) to the "pythonic" equivalent (__call()__, function object, decorators, context managers, etc). And yes, I am being a bit hand-wavy at the moment.

If it is a practice exercise, we have a bit more flexibility, although we will (eventually) have to do the concept breakdown and functional ---> python mapping anyways.

Let me know - and happy to have you as a contributor! 🌟

BethanyG avatar Sep 16 '21 15:09 BethanyG

So, I guess it would be a practice exercise, since functors etc. aren't really central to learning Python. What do you think? Is that the correct criteria?

samfrances avatar Sep 16 '21 17:09 samfrances

Well... (playing advocate with my devil horns on) I don't know if the distinction should be that strict. Python is mulit-paradigm - and functional-style programming is very very popular.

Of course, Python is not a functional language, but that doesn't mean that you cannot use functional constructs or style -- and indeed, there are many places where you can do so, and where it helps simplify or clarify code. But in order to do it well, it takes knowing what tools Python gives you, and where you need to adapt, based on the underlying object model. And there are places where you might need to make different choices for performance or other limits. So it may very well be central to learning Python. 😉

We'd want to be careful about terms and tools. But ... that might be worth exploring on a "functional python" section/branch of the concept tree......

But you can also do a practice exercise. I do not want to sign you up for work you don't want to do! And also? This does not have to happen all at once. This can be a longer-term plan or feature. 😄 We are in early days with the concept exercises, clearly.

BethanyG avatar Sep 16 '21 18:09 BethanyG

Ok. I think I should go away and read those contributing docs and then get back to you. Thanks @BethanyG for your guidance. :)

samfrances avatar Sep 16 '21 18:09 samfrances

https://skeptric.com/python-maybe-monad/

But also I would like to encourage you to work on some exercise that would test if one could implement functions that could handle weird edge cases like empty lists, strings or Nones.

It would improve "Error Handling" syllabus.

kwikiel avatar Sep 30 '21 22:09 kwikiel