Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Declarative languages are characterised by having the programmer specify _what they want_ but not _how to get it_ (i.e to get a sorted list, you would specify that the elements are in increasing order, but not the specific algorithm to use). In contrast, functional languages are characterised by treating functions as first class values (amongst other things, but these are harder to summarise).

Prolog for example is a declarative language, Haskell is a functional language.



Someone can correct me on this, but I've never seen this distinction you're making anywhere else. And, it doesn't make sense to me either. The wikipedia page[0] for FP says that FP is a "declarative programming paradigm". Can you give me an examplel of a "functional" piece of code that is "not declarative"?

[0] https://en.wikipedia.org/wiki/Functional_programming


Prolog is a declarative language but not a functional language. Hence functional languages and declarative languages are not equivalent. Functional languages are not just defined by lacking side effects but also by using functions as first class citizens, meaning that SQL isn't a functional language either.


Thanks!


Python and Scheme are the two classic examples of non-declarative functional languages; they are both instructing low-level VMs to mutate machine state, but also both have functional-programming tools and first-class functions. The Scheme (set!) form is a great example of imperative mutation within a functional paradigm.


Your definitions are pretty much orthogonal. I would consider Haskell functional and mostly declarative.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: