DEV Community

Discussion on: Functors, Monads and better functions

Collapse
 
hoffmann profile image
Peter Hoffmann • Edited

Sorry for my short first reply I was very frustrated reading the n-th "simple" explanation. My approach would be completely different. What you are doing is describing Category Theorie like a farmer would describe her "functor-monard-object-arrow-a-b-catgeory-unit"-land. What I need is a way from "function, method, class, object"-land to you land.

First of all: About which objects are you talking in when you say "CT deals with objects…". Is this an abstract term for something not related to OOP objects or just what I'm used to?

If you are talking about arrows I will think about functions in the classical programming approach. Use examples to explain how the theory is translated into functional programming.

Haskell and Elm are known for their tight connection to functional programming but Javascript is also very powerful and much more common. Adding examples from JS broadens your target audience.

You introduce "Category", now I realy need an real world example about what you are talking otherwise it's just abstract. And what is the "structure of arrows"? And why could that mean "F a ≠ F b"?

Then you go on with a functor from an object but you just wrote, an functor connects a category to another one. And what is an Unit? Is an Endofunctor the real name of an identitiy functor?

In the next paragraph you talk about the Maybe/Optional and Cmd type. Never heard of it. Also e.g. in PHP, JS, Python an Array is absolutely a real type as it doesn't have to be typed.

Next I assume a typo (or isn't it?): "iff. we" -> "if we". Then the sentence I quitted: "and produces something isomorphic to identity if identity is provided as input". Well what?

Sorry I didn't get it. Maybe I'm just to old and my brain plasticity is below what is needed. But I still don't get the concept.

Thread Thread
 
drbearhands profile image
DrBearhands

It looks like we just have very different backgrounds. Your feedback is very useful, I will use it to improve the post.

One of the big problems with learning / teaching FP is that people from IP (imperative programming) have expectations that don't hold for FP. So rather than lacking brain plasticity, you know too much. It is a common problem to which I have probably not given enough attention. To address your specific concerns:

About which objects are you talking in when you say "CT deals with objects…". Is this an abstract term for something not related to OOP objects or just what I'm used to?

Not the same. Objects in CT are pretty much undefined, nothing more than something for arrows to connect. So you can have a category where CT objects are OOP object, but you can also have a category where objects are apples, or the number 5, or the belief in a higher power.

In programming we are mostly concerned about the cases were objects are types (FP) or states (IP) and arrows are functions (FP) or commands (IP).

If you are talking about arrows I will think about functions in the classical programming approach. Use examples to explain how the theory is translated into functional programming.

You've got it, arrows are isomorphic to functions ("isomorphic" means they have the same 'shape', they act the same).

Javascript is also very powerful and much more common.

The isomorphism doesn't work well for javascript because it is neither statically typed nor functional (being functional requires no side-effects, not just passing callbacks around).
This series is about the theory of functional programming, not so much about how to make JS look like Haskell. There's other posts doing that pretty well.

You introduce "Category" [...] Is an Endofunctor the real name of an identity functor?

I should have spent more words describing all this. It is all, indeed, very abstract though.
It's a bit much to address in a reply, please give me some time to fix the post.

Also e.g. in PHP, JS, Python an Array is absolutely a real type as it doesn't have to be typed.

I mentioned how the isomorphism doesn't really hold up for weakly typed languages. Essentially those languages don't have types, so they also don't have type constructors.

"Monads" in js are more monad-inspired.

Next I assume a typo

Nope. "iff." is short for "if and only if".

and produces something isomorphic to identity if identity is provided as input

Expressed in JS, a function map(callback) should return a callback cbk that acts just like a => a, i.e. cbk(foo) === (a => a)(foo).

Two functions are isomorphic if they produce the same result for the same input.

Thread Thread
 
hoffmann profile image
Peter Hoffmann

Thank you for spending so much effort on explaining everything much clear. I can't say I completely understood CT-land but it's a lot clearer.