Hacker News new | ask | show | jobs
by kyllo 4189 days ago
Nice.

I like this more for a functional idiom:

    case foo of 
        TUESDAY => "Taco Tuesday"
        | _ => "Not Taco Tuesday"
Or this:

    (cond (= foo TUESDAY)
        ("Taco Tuesday")
        ("Not Taco Tuesday"))
All programs, at heart, are imperative

Yes, but only because the underlying machine architecture is imperative, right? If you had a chip that could evaluate pure functions with no mutable state (like a Lisp Machine that used a purely functional dialect of Lisp) then you could have programs with no underlying imperativeness.

But in a perhaps more relevant sense, in languages like Haskell or Prolog it is possible to write a program with no imperative state manipulation happening at the programmer's working level of abstraction.

Still, this really has nothing to do with determinism.

Also, I like SQL as an example of declarative programming.

    SELECT * FROM USERS
    WHERE JOIN_DATE = "20150106"
That is a declarative program; the SQL engine it's run on decides the underlying imperative implementation of the solution at runtime. It is also deterministic in that when it's run on the same database containing the same data multiple times it will return the same result.

From what I know about Prolog, I understand it's similar in this regard.

1 comments

Look at your case statement. In most languages, if you swapped the order of TUESDAY and _, you'd get different results.

An actual declarative language would choose TUESDAY over _ because it's the most specific match, and not because it matched it first.

Yes, good point, but this was not meant to be an example of declarative paradigm, just functional paradigm. It's SML, which is not a particularly declarative language. Haskell is a little bit more declarative but AFAIK its pattern matching works the same way as SML.