7 ms·
As a functional programmer myself, I have the same confusion. As best I can tell, category-theory a cargo-cult thing ("I want to look like the type of engineer
by zug_zug 7y ago
As a functional programmer myself, I have the same confusion.
As best I can tell, category-theory a cargo-cult thing ("I want to look like the type of engineer who CARES about monoids [because if I use words you don't know I'm smart]" much in the same way hipsters claimed vinyl sounds better).
I'd like to be wrong about this, but I've already met a handful of "phonies" who rant and rave about this stuff, but when I ask them "How does labeling an array a monad help me?" or even "Is a hash-map a monad?" they are completely stuck.
- crimsonalucard 7y agoLabel the string as a functor and think about lifting the array into the string functor and doing string manipulation to change it to a dict, then lift it back into a dict type. String manipulations of a lifted type in "string space" can be faster and more efficient then actually manipulating it in "type space"
- edflsafoiewq 7y agoWhat?
- alexandercrohde 7y agoThis is exactly what I mean. I can't tell if that's a joke or not.
- crimsonalucard 7y agoNot a joke. Take a look at my response to the other guy. I clarified my point with a thorough example. Please note that I was somewhere else and on the phone when I typed my initial response so forgive me for the brevity and lack of clarity. Hopefully the new response will clear things up. Anyway... I think theres a good chance that you simply aren't grasping what the category theory fans are saying. Hopefully you grasped what I'm saying.
- crimsonalucard 7y agoApologies. I was on the phone typing the above. Still, remarks like "What?" that provide no information or context are against the rules on HN. Just FYI. The OP said that there's no point in labeling an arbitrary type as a functor or monadic value. I'm going to use an example to illustrate how there is a benefit in being aware of this concept. I will be using a "String Monad" in my example. Imagine you have some type, like in the initial example. And you want to convert that type into another type. I'll give you an arbitrary example using python: You want to convert this: {1:2 ,3:4, 5:6, 7:8} To this: [1,2,3,4,5,6,7,8] You can do this via loops or you can "lift" the dictionary type from "type space" to "string space" via the python functor str(): lifted_dictionary = str({1:2 ,3:4, 5:6, 7:8}) This is similar to movement between two categories or objects via a functor. You see similar techniques in other fields of engineering when say someone "lifts" something from cartesian coordinates to polar coordinates. Which is why I'm using the word "space" it's similar to how I'm shifting representations of coordinates to have an easier time with certain calculations. Then you do your type manipulations in "string space" rather then on the type itself. So it all ends up being string manipulation operations to get from the string "{1:2 ,3:4, 5:6, 7:8}" to the string "[1,2,3,4,5,6,7,8]". I didn't use regexp in the example below but you get a huge performance boost if you use that instead. lifted_array = "{1:2 ,3:4, 5:6, 7:8}".replace('{','[').replace('}',']').replace(':',', ') #computed value is a string of the form: "[1,2,3,4,5,6,7,8]" Then you use the opposite functor from str() to lift the value back into "type space" array = eval(lifted_array) Here eval() is the opposite functor to str() Type conversion complete. The full code: original_dict = {1:2 ,3:4, 5:6, 7:8} array = eval(str(original_dict).replace('{','[').replace('}',']').replace(':',', ')) #value of array is [1,2,3,4,5,6,7,8] Essentially you use functors to lift your data structures into other categories for easier conversion, then you simply bring the stringified type back down into regular "type space". So in short I took types and lifted it into the String Monad or "String Category" or whatever you want to call it, then brought back down into types. It seems like an arbitrary way to do type conversion but using regexp to do string manipulation in place of a for loop that unrolls the dictionary is more performant and faster. Think about preserving order as well. When I convert the dict type into string space, ordinal properties of the string itself will be enforced on the dict. SO the keys in the dict will follow the order they appear in the string as will the array string that it is converted to. This technique utilizes category theory. The categories you are lifting to must be isomorphic to the origin category, you must understand the notion of functors (or monadic values) to really get it.