3 ms·
That's the definition of "referentially transparent", not declarative. I don't think the FP community has or attempts a shared definition of "declarative". It's
by tel 12y ago
That's the definition of "referentially transparent", not declarative. I don't think the FP community has or attempts a shared definition of "declarative". It's just sort of a feeling and, as such, has all the associated woo woo properties.
For a counterpoint from a (contentious) expert, try http://existentialtype.wordpress.com/2013/07/18/what-if-anything-is-a-declarative-language/ http://existentialtype.wordpress.com/2013/07/18/what-if-anyt.... Here, Harper lays out 8 definitions of "declarative" which might have force. You don't have to agree that this list is comprehensive, but I know that I've personally heard arguments using most of those "definitions".
In http://existentialtype.wordpress.com/2013/07/22/there-is-such-a-thing-as-a-declarative-language/ http://existentialtype.wordpress.com/2013/07/22/there-is-suc... Harper argues a particular definition of "declarative" near to his heart. The critical could argue that his earlier list was aimed at nothing more than exposing this definition. Harper's idea is that declarative languages are ones with "mathematical variables" instead of just "computer science-y assignables or slots".
I don't care whether or not that's your definition of declarative as well, but I think variable v. assignable is a very nice, hard distinction between languages.
- innguest 12y agoThe difference to me is maybe not as formal, though if I had to pick one I'd pick your definition: declarative is when variables are like mathematical variables, and not like turing-machine memory cells. To me the difference is in the level of abstraction. In a non-declarative language, one way to reverse a list is to traverse it, remembering the last item, and change the pointer of the current item to point to the remembered item (if there's no remembered item, the current item is the head of the list, and we make it point to the list terminator). So we have to say exactly how to build the value we're interested in, the reversed list. Whereas in a declarative language, I simply give a definition of what a reversed list is, without saying how to go about doing it. In fact the computer is free to come up with any way it wants to do this, and I can define a reversed list as being the fold of construction over that list. Prelude> foldl (flip (:)) [] [1,2,3,4] [4,3,2,1] Which does not force me, the programmer, to use any mutable memory cells; in other words this operation is loosely defined enough that it could be "run" both destructively and immutably. The fact that the function declaration does not specify the implementation is what I usually mean by "declarative".
- tel 12y agoTo be clear, this is Robert Harper's definition. I just like it :)
- tel 12y agoI think there's generally a UI/UX notion of "declarative", the "declarative feel". There's also that whole list of technical definitions. The mismatch is one of category as much as of definition. For instance, I would analyze your foldl example as being driven by the fact that foldl has a denotation above its implementation. But, as Harper notes, all languages have a denotational semantics if we choose to recognize them and it's difficult to say what it means for a denotational semantics ti be "better" than another in any technical sense. So what is declarative? In my mind, it should really only be a UX term. I think technical definitions are debated because of the category mismatch alluded to earlier. I think notions like "equational semantics", "denotational semantics", "referentially transparent", and "variable" are the right technical terminology.