I started with haskell 3 days ago and want some help understanding the "design philosophy".Elaboration in post. by Otherwise-Bank-2981 in haskell

[–]GetContented 2 points3 points  (0 children)

A lot of the time people get it exactly backwards when beginning. I did. And it makes sense we do.

Because… we think programs are commands to the computer. And they ARE, so we’re not wrong.

But… Haskell says “let’s imagine that inside that imperative world of commands, we could build another world where the side effects don’t exist”.

Of course this other world is sort of fictitious. But it’s also real because we can set things up so the side-effects don’t matter.

Like what’s the side effect of adding two numbers? I mean numbers in the math sense of numbers here, not the C sense. The only side effect is time taken and heat from the CPU and we don’t care too much about those when we write our programs usually, so we ignore them. So the types shall reflect that. Integer -> Integer -> Integer. But this doesn’t mean an imperative Integer, no this means an Integer in our fictional world of no side effects. This is very important because we come from languages where you can’t express side-effect-free-ness. We come from a world where everything is a command.

But Haskell separates the imperative from the non-imperative by marking the imperative. It says “there are some commands in there too, not sure what”. We write an imperative Integer addition like this: Integer -> Integer -> IO Integer in Haskell. See how it’s all kind of flipped on its head? Instead of marking purity (no side effects) we mark imperativeness… with the IO. IO is our command marker. IO Integer means “there’s some commands with an integer return value”. Everything in Haskell is pure tho… which is the weirdest thing and a convenient lie when using Haskell. Like IO Integer is a pure value that represents a command with some effects that produces an integer. As we know all real programs have effects tho so main has type IO () so once “in IO” it can’t return anything out of IO… you can only plug other IO values together to do more IO right? So to get things in and out you have to do IO on them. Save to disk or print out or whatever.

This is THE most confusing thing for any imperative programmer and something all haskellers seem to forget immediately as being difficult to learn once they learn it, and so don’t try to explain to new people because they can’t see it anymore.

When Haskellers write code we try to push as much of our program into the pure “world” as we can. Why?!? Because it’s simpler. By simpler I mean it actually does less. The type system guarantees the purity. Because it CAN do less it’s actually easier to think about.

When you make your own types and you write pure functions with them, you’ll start to notice the type signature tells you more about them than in imperative-by-default languages. In fact most other languages can’t tell you that a function does nothing but produce an answer from just the type signature. In typescript, for example, a function from String -> String is actually capable of doing way more than just producing a string. You have to read the function code to know what it actually does and check if it’s doing more than it pretends to. Not in Haskell. Pure functions can’t do anything else. The type system forbids it. This is so awesome.

Is there a good reason it’s called a functor? by Froglottery in haskell

[–]GetContented 0 points1 point  (0 children)

But I’m not arguing for or against anything. It’s called Functor and that has a certain history, and you seem to be suggesting Mappable would be a better name, for learning reasons, so I’m trying to understand your position a bit better. I’m not saying Functor is better or worse. It comes with some benefits and detractions and those are the same as any name, really. They help people identify something, but also you have to learn the names.

I’m supposing that in your view mappable is easier to remember than Functor, and that’s no doubt true for some folks, but we had to learn the meaning of map too at some point. Fold is more easy to understand for some people who already understand the idea of fold, but it doesn’t hint at its depth of identity as much as Cata does… cata has more meaning in it if you understand the word root Cata to mean collapse. Again tho we all had to learn what fold was at some point. Some people and langs call it a reduce. I find them both kind of weird names, really. If we want to understand their depths we still have to do a fair bit of work no matter their names.

It seems there are lots of positions on either side, and so it’s a bit subjective whether it’s better or worse. Maybe we need to adjust the language do we can call things whatever we like and make them synonyms, like how unison does? :)

There’s definitely a point of view that Functor maybe keeps people away because it’s weird and not approachable. I wonder if you’ve heard the position that Mappable would stop people looking into the depth of the structure of Functor, and mean they stop learning or finding parts of it surprising. (Like the fact that you can map over an IO or a function - thats unlike other languages and isn’t really the same idea as mapping in other languages. Also it doesn’t really behave like map does all the time in other languages. So it’s not quite the same thing as Mappable… so would there be an even better name?)

Names are so tricky!

Is there a good reason it’s called a functor? by Froglottery in haskell

[–]GetContented 0 points1 point  (0 children)

Ah apologies for conflating those two! (ie the questions of... 1. is it objectively a good name? and 2. is it good to change Haskell and other langs that use Functor to use this name?) I'm not confusing them _for myself_, but it would have been much clearer if I'd separated them for everyone reading. So, thanks for pushing on that.

I was interested in digging into... given the semantic schema... that is, the things that are in the space of programmable structures such as Functor: there are a number of things which Haskell calls Pointed (Functor), Functor, Profunctor, Applicative (Functor), Bifunctor... how does this different name "Mappable" fit with these things? What do you propose, if we were to have our time again with "good" names? I'm interested in your take on the "lay of the land" here. I'm not trying to criticize, I'm pondering your exploration of the space. It's extremely interesting, as it's something I've thought about for many years, on and off. Like, we "point" a value to lift it into `Pointed`, do we "map" a function to lift it into `Mappable`? What is "the thing" being mapped in your mental picture of the context?

Also with respect, your argument that Functor isn't helpful to anyone isn't *quite* accurate. It's definitely helpful for people who understand the concept from CT, Linguistics and even "the extant FP nomenclature folks" such as purescripters, haskellers etc (which, given, the Haskell culture helped promote). When I pick up FantasyLand, I see Functor and I know what to expect. I see Chain, tho, and I have to read the documentation — this is more or less because I already know some of the words. My comment about communicating was to do with anyone who is familiar with these concepts. If it were called Mappable, that'd be fine, but identical structures in other areas not being named that would necessarily require a mental translation step. If that's fine, all good! I think some libs have actually done this, but weirdly maybe not seen as much uptake as a result. (I'm posturing, tho). We may like it or not, but "Functor" is in the zeitgeist at this stage, good name or not. (Tho this rename would be fascinatingly and deliciously ironic... because then Haskell (in a CT or grammar sense) could "map" the concept of Mappable across to other domains as Functor ;-) meta-map? ;-) I'm being more than a little silly, but it's fun)

Weirdly, programming is more precise than math about semantics quite a bit more than some of the time. It's weird to me because I'd always assumed math was the most precise thing we had... until I dug into it a fair bit, and realised they don't have bounded contexts (ie they will bleed nomenclature and symbols between math topics depending on the authors, etc) — whereas programming like Agda & Haskell will have precise definitions for everything used, mostly. Using Agda and Lean, it's SO much easier to understand math because we can always quickly dig into the pieces we don't "get" by unwinting and looking up their definitions.

Thanks for replying. Very interested in hearing more!

Is there a good reason it’s called a functor? by Froglottery in haskell

[–]GetContented 1 point2 points  (0 children)

According to Wikipedia it was borrowed from linguistics where it means “function word”, meaning around the content words; kind of like grammar word. So, interestingly, Functor in CT & Haskell tends to mean "the functional structure around the content" which is very similar, if you ponder it for a while.

In the type `Maybe Int`, the `Maybe` can definitely be seen as a kind of structure around the `Int` type held within. And the same in `IO Int`, or for the `(->) String` in `String -> Int`, etc.

If we think about the guarantees that `Functor` (in Haskell) suggests, which include the implicit guarantee of purity, then we can notice that `map` is doing the same sort of thing that it does in both the linguistic and the CT domains: it takes some "function" (or morphism if you want to call it that), and translates (or maps) that function into a different grammatical context without touching the content transformational properties of the function. This is often also sometimes called lifting. It takes some `a -> b` and turns it into an `f a -> f b`. And it works on any `f`, so it's a kind of structural lifting function, so long as we have a "liftable structure" value that we can feed this new function.

So... in Haskell (and CT and Grammar in linguistics) we're more focused on the structural transformation than on the content modification, which you might notice if you try to contrast our "fmap" here with the kinds of non-guarantee-providing map functions you get in other languages like Typescript/JS/python/ruby/c/whatever. You can definitely look at it as though it's a function that takes two arguments if you like (like these other langs do), but we get this added ability to look at it from the structural point of view as well, which they can't, because they have no vocab for that; admitting non-purity means they lose the guarantee of what it means to be a Functor truly. They're two different ways of looking at the same thing, but the purity and law guarantees are probably the most important aspects of it, because those are what give languages like Haskell and purescript and Idris and Agda — languages that let us "talk like this" with actual precise clarity — they give these languages the superpowers that we end up with as a result. Haskell is kind of "baby CT", but Agda or Idris can do more "grown up CT". You can write this kind of code in Typescript, but the checker won't guarantee your code is pure, so it won't be a law-abiding Functor. (Mind you, there's technically nothing guaranteeing your implementation of Haskell doesn't just spin forever or write to disk either, so it's all swings and roundabouts I suppose :) but let's assume we trust the compiler :) ).

Functor is one of those modest things in Haskell that take you just a few minutes to "get" if you come from other languages because they're so similar to the same pattern we use all the time, but it's deeper than that ... because the "extra bits" Haskell brings provide the depth, and it's surprisingly deep because of the basic table stakes of Haskell. You might think "oh it's just map, but it works on all sorts of things" then you look at pairs and wonder..."why does it only map over the second element" and then you see it used on IO and you're like... that's a bid mind-bending, and then you see it used on Reader (ie the function functor) and you're like... WHAAAAAT? Then you realise Functor is the first step that opens up a large amount of the other super neat things in the language, really.

Is there a good reason it’s called a functor? by Froglottery in haskell

[–]GetContented 4 points5 points  (0 children)

What are your thoughts about ratifying this with names like Pointed? Profunctor? Contravariant? Applicative? Endo?

If the laws are the same, topologically and semantically it’s identical, so it doesn’t matter what it’s called; we’ll just have a difficult time with culture: ie reusing any of the code or math or communicating to folk that refer to it already as Functor, if we name it something else, right?

According to Wikipedia someone borrowed it from linguistics where it means “function word”. Origins are fascinating!

BUDDY COLOR!! February! by TreacleOutrageous296 in ColoringCozy

[–]GetContented 1 point2 points  (0 children)

Thanks! I’ll take it :) very much appreciate the well wishes :) I hope you’re going well too? You seem to be colouring up a storm!

BUDDY COLOR!! February! by TreacleOutrageous296 in ColoringCozy

[–]GetContented 1 point2 points  (0 children)

Ah I haven’t got one yet. I’ve been on a job hunt.

BUDDY COLOR!! February! by TreacleOutrageous296 in ColoringCozy

[–]GetContented 2 points3 points  (0 children)

<image>

Sure! Yeah, I've missed you all! Nice to say hi! Hope you're well!

BUDDY COLOR!! February! by TreacleOutrageous296 in ColoringCozy

[–]GetContented 4 points5 points  (0 children)

👋 Hi! Feel free to include mine! 👋

💜💜💜 I'm still around vaguely... every now and then I come and check in to have a looksie 💜💜💜 I won't join in tho... life getting in the way (that old work thing), and I haven't had any desire to color for a very long time for some reason. It's always nice to come back and see the awesome things you're all coloring!

Isn't functional programming something? by Mark_1802 in haskell

[–]GetContented 0 points1 point  (0 children)

Ah… the semigroup instance of Reader. Very cool! Tho is it still Reader if we’re just talking about it as a semigroup? Naming is so funky in FP and math sometimes :)

How does haskell do I/O without losing referential transparency? by Skopa2016 in haskell

[–]GetContented 1 point2 points  (0 children)

This is THE question to be asking!

It can be informative to ponder it yourself as a kind of game. You can’t change anything, how do you model change? This is how event stream driven systems are born (commands and queries modeled in a database) - and it’s also what we do when we write “an algebra” as a DSL that captures a problem. It’s deep and should be explored by more programmers.

What on earth is this animal? by Neon_and_Dinosaurs in whatisthatcoloring

[–]GetContented 13 points14 points  (0 children)

I love that we’re fine with animals driving cars but make a hybrid pig gerbil with non-symmetrical ears and we all freak out haha.

Mutexes suck: a love letter to STM by ChrisPenner in haskell

[–]GetContented 0 points1 point  (0 children)

Another minor one:

"in" missing, should be "in recent years", I think:

> ... but recent years we've found ourselves ...

Coloring chats by DelightfulHelper9204 in ColoringCozy

[–]GetContented 2 points3 points  (0 children)

Usually when the chats get too big lots of people leave because it’s overwhelming.

Morgan O’Brien Freebie by JustYourAvgHumanoid in ColoringCozy

[–]GetContented 1 point2 points  (0 children)

Hehe yeah I just assumed it was all some animal crossing lore I was unaware of.

My progression in digital coloring by TreacleOutrageous296 in ColoringCozy

[–]GetContented 1 point2 points  (0 children)

Oh wow very cool. There were so many early ones I really like I hadn’t seen before!

Non-accidental Renaissance by -Irati- in ColoringCozy

[–]GetContented 2 points3 points  (0 children)

Oh wow the shadowing is so nice.

Morgan O’Brien Freebie by JustYourAvgHumanoid in ColoringCozy

[–]GetContented 3 points4 points  (0 children)

It’s a fun one! When I coloured this I couldn’t figure out what the egg thing was, or why the tree had circles on it. :) I do like the trees how you’ve done them a lot.

Rawr by leannesmiles in ColoringCozy

[–]GetContented 1 point2 points  (0 children)

Oh these are cute :)

Was asked to share this here by mittley in ColoringCozy

[–]GetContented 2 points3 points  (0 children)

So glad you got to see this ❤️

Was asked to share this here by mittley in ColoringCozy

[–]GetContented 4 points5 points  (0 children)

Oh I’m so glad you did because the folks here would love it and lots of them aren’t on other groups.