4 ms·
Functional and declarative are the same to me
by pharmakom 4y ago
Functional and declarative are the same to me
- eyelidlessness 4y agoI think what the article intended by “declarative” is roughly occupied by the “logic programming” paradigm and DSLs like SQL. If my intuition is right, they have a lot of conceptual overlap. But they differ mostly in how much they realize a goal of “what, not how”.
- epgui 4y agoThey're related, but "declarative" is a broader category that includes relations. Functions are a special case of relations (see also: prolog, datalog, sql...).
- manmal 4y agoYou can write declarative code in an imperative language, and you can write non-declarative code in a functional language (eg IO monad). So IMO they can’t be related. That’s assuming that „declarative“ means „describing outcomes rather than describing process“.
- epgui 4y agoYou can write functional code in an imperative language and you can write imperative code in a language like Haskell, but that’s irrelevant.
- manmal 4y agoThey are orthogonal. React (FC) is a declarative _and_ functional approach. The declarative part is where React code describes what should be rendered, instead of adding/removing DOM elements manually. The old React is not 100% functional (partially OO), but it still is declarative.
- epgui 4y agoThey're not orthogonal. I believe one is a subset of the other, but at a minimum they overlap.
- manmal 4y agoUsing extremes for both, that would mean there is overlap between languages like Haskell and languages like SQL? (Edited for clarity)
- anonymouskimmer 4y agoI'm a biologist that doesn't understand what's being talked about on this thread at all (a definition of "state", and its relation to other computational parameters would be nice). But I think I can pull an analogy from ecology that might be useful here. When a bird population starts speciating along, say, the arctic circle, you have a line of a bunch of closely related sub-species that can interbreed with the sub-species nearest them. Sub-species 1 ... Sub-species 2 ... Sub-species 3 ... Sub-species 4 ... 1 can breed with 2. 2 can breed with 1 and 3. 2 can't breed with 4 because they are too far apart, but if a 4 came to the territory of a 2 they could breed. Etcetera. Eventually You get a whole circle of interbreedable sub-species as they spread across a circle of arctic latitude around the world: 1 ... 2 ... 3 ... 4 ... 5 ... 6 ... 7 ... 8 ... 9 ... 1 But once you get to that point you find that sub-species 9 and sub-species 1 can't, or won't, interbreed anymore. They are now two entirely separate species despite coming from the same origin and living right next to each other. However none of them can interbreed with a complete separate lineage, such as wolves. TLDR: The overlap is before the extremes, not between them.
- epgui 4y agoWell… I’m not sure how helpful that example is, but yes you could probably find something in common between SQL and Haskell, and on the other hand, no, what I said did not mean that. Look up Graham Hutton’s writings on relations. He has published quite a bit about this, and he knows a thing or two about functional programming.