News for hackers. Stuff that matters.
Re:Show HN: Python library for functional programming by lmm on Thursday December 14, 2017 @10:11AM (#15922815)
Functional style makes it easier to have a natural semantics that corresponds directly to the language proper: you can use a small-step semantics where evaluation is just reduction, and you then have a very simple and natural denotational semantics (the denotation of an expression is just the value it evaluates to) that obviously corresponds directly to your operational semantics. All that is much harder to do with programming styles that make use of pervasive, implicit state.
Re:Show HN: Python library for functional programming by catnaroek on Thursday December 14, 2017 @10:39AM (#15923074)
A semantics is a property a programming language, not the style you happen to program in.

---

@lmm

> In practice no practical language provides formal semantics for the entire language

Programming languages are mathematical objects and always have a formal semantics, regardless of whether someone has taken the trouble to write it down or not.

What I'm saying is - the formal semantics that most languages have preclude the existence of compound values. Without those, you can't define interesting functions, and thus you can't program in a functional style.

Re:Show HN: Python library for functional programming by lmm on Thursday December 14, 2017 @05:26PM (#15927788)
Responding to edits:

> Programming languages are mathematical objects and always have a formal semantics, regardless of whether someone has taken the trouble to write it down or not.

Not true for the usual plain-english meaning of "programming language". Plenty of things we call programming languages take a "the implementation is the spec" view, or simply can't be assigned any useful semantics in a way that's at all aligned with the defining characteristics of the language in question. Even in, say, Haskell, io explicitly lacks formal semantics.

> What I'm saying is - the formal semantics that most languages have preclude the existence of compound values. Without those, you can't define interesting functions, and thus you can't program in a functional style.

Python tuples are perfectly cromulent compound values. Python has a bunch of builtin classes for which the equality operators that are available in the language are all kind of useless, sure, but that's true in almost all languages.

Re:Show HN: Python library for functional programming by catnaroek on Thursday December 14, 2017 @05:41PM (#15927921)
> Plenty of things we call programming languages take a "the implementation is the spec" view,

And do you think the implementation isn't a mathematical object itself?

> or simply can't be assigned any useful semantics in a way that's at all aligned with the defining characteristics of the language in question.

This is a contradiction in terms. By definition a semantics is a mathematical descrpition of the meaning of a programming language, i.e., the behavior of its programs. Sometimes a semantics exposes significant differences between the mental model of programmers and what a programming language really is, but the solution is not to turn a blind eye to reality.

> Python tuples are perfectly cromulent compound values.

So long as they have object identities, they are not values. Values are merely represented in memory - they truly exist in the language's semantics.

Re:Show HN: Python library for functional programming by lmm on Friday December 15, 2017 @06:27AM (#15931073)
> And do you think the implementation isn't a mathematical object itself?

Only if you're taking the Tengmark "mathematical universe" view. The implementation is not necessarily any more mathematical than, say, a table.

> This is a contradiction in terms. By definition a semantics is a mathematical descrpition of the meaning of a programming language, i.e., the behavior of its programs. Sometimes a semantics exposes significant differences between the mental model of programmers and what a programming language really is, but the solution is not to turn a blind eye to reality.

The meaning expressed in a language is some alignment of what the writer intended and what the reader understood. If different readers don't reach a shared understanding then there is no meaning. It would be desirable for our programs to always have meanings that aligned with their behaviour, but we shouldn't turn a blind eye to the fact that many programs don't.

> So long as they have object identities, they are not values. Values are merely represented in memory - they truly exist in the language's semantics.

Any practical programming language will give you some way to find the memory address of a particular value, so values that we usually consider as semantically identical are not actually indistinguishable in practice. We deal with this by only assigning semantics to a subset of the language that excludes those operations. Python without "is" may be more obviously a subset than, say, Haskell without unsafeCoerce, but both are subsets.

Re:Show HN: Python library for functional programming by catnaroek on Friday December 15, 2017 @04:26PM (#15935305)
> It would be desirable for our programs to always have meanings that aligned with their behaviour, but we shouldn't turn a blind eye to the fact that many programs don't.

The meaning of a program is its behavior, period. If reality doesn't agree with your views, it's your fault, not reality's.

> Any practical programming language will give you some way to find the memory address of a particular value, so values that we usually consider as semantically identical are not actually indistinguishable in practice.

Standard ML doesn't give you any way to get the memory address of a particular value, so values that are semantically identical are actually indistinguishable in practice.

> We deal with this by only assigning semantics to a subset of the language that excludes those operations.

That doesn't make sense. Semantics is a property of the real programming language you are using, not the fictitious one you wish you were using.

Re:Show HN: Python library for functional programming by lmm on Friday December 15, 2017 @06:58PM (#15936365)
> The meaning of a program is its behavior, period. If reality doesn't agree with your views, it's your fault, not reality's.

That's not the usual meaning of, well, meaning.

> Standard ML doesn't give you any way to get the memory address of a particular value, so values that are semantically identical are actually indistinguishable in practice.

Just tried it to be sure:

    fun address i = Unsafe.cast(ref i) : Int32.int ;;
    val a = 4 :: nil ;;
    val b = 4 :: nil ;;
    address (a) ;;
    address (b) ;;
    address (a) ;;
And yep, a and b are semantically identical values but distinguishable in practice:

    val address = fn : 'a -> Int32.int
    val a = [4] : int list
    val b = [4] : int list
    val it = ~175003712 : Int32.int
    val it = ~174998232 : Int32.int
    val it = ~175003712 : Int32.int
Re:Show HN: Python library for functional programming by catnaroek on Saturday December 16, 2017 @04:39AM (#15938698)
SML/NJ is not an implementation of Standard ML. It's known to be non-conformant in several ways: http://mlton.org/SMLNJDeviations
Re:Show HN: Python library for functional programming by lmm on Monday December 18, 2017 @05:36AM (#15950723)
If SML/NJ doesn't count as Standard ML then I'd say Standard ML doesn't count as a practical programming language.
Re:Show HN: Python library for functional programming by catnaroek on Wednesday December 20, 2017 @11:12AM (#15970810)
I use MLton and Poly/ML on a daily basis. No problems with them at all.
Re:Show HN: Python library for functional programming by lmm on Thursday December 14, 2017 @12:31PM (#15924268)
In practice no practical language provides formal semantics for the entire language, only for restricted subsets of it i.e. particular styles within the language.