Live data from Hacker News

When if is just a function

ryelang.org

81–90 of 111 posts

Re: When if is just a function

#81
post #59

I'm definitely missing some key insight because after reading the article I felt it was a strawman argument. Python already has conditional expressions, which already allow 'x if (predicate) else y'. Therefore in Python if is already equivalent to a function, and is composable. Once you realize this, and also understand that Python has logical operators that can short-circuit, all Python examples feel convoluted and…

Python was used as an example because people know Python and reader can compare it to something known. I wasn't trying to make Python look awkward. I was trying to write equivalent Python, you are very much welcome to suggest improvements to my Python examples. Other languages could be used instead of Python, for example Javascript. But I feel Python is more contained language, with clear ways to do thing (I guess I…

> Python was used as an example because people know Python and reader can compare it to something known.

I don't think you understood the point I made.

My point is that Python supports conditional expressions for years.

Support for conditional expressions already means that in Python indeed "if is just a function".

Therefore, the whole premise of the article is null and void, and the article is thus pointless.

This is evident to anyone who is familiar with Python. If you have any experience with Python and you are familiar with idiomatic Python and basic features such as list comprehension, you are already widely aware how "if is just a function".

> I wasn't trying to make Python look awkward. I was trying to write equivalent Python (...)

Except you didn't. You failed to even acknowledge that Python already supports "if is just a function" with basic aspects such as list comprehension.

This basic aspect of Python is covered quite prominently in intros to Python, but somehow you failed to even acknowledge it exists, and proceeded to base your argument on a patently false claim.

Re: When if is just a function

#82
post #74
post #69

Earlier quoted context omitted.

yourIf == myId

No instance for (Eq (MyBool a0 -> a0 -> a0 -> a0)) arising from a use of ‘==’ Undecidability of function equality aside, we could indeed define "myIf = id" instead.

Fair point, though if I remeber correctly there is only one function with type a->a and so we get equality automatically.

(This may be untrue in the presence of the likes of unsafeCoerce.)

Re: When if is just a function

#83
post #59

Earlier quoted context omitted.

Python was used as an example because people know Python and reader can compare it to something known. I wasn't trying to make Python look awkward. I was trying to write equivalent Python, you are very much welcome to suggest improvements to my Python examples. Other languages could be used instead of Python, for example Javascript. But I feel Python is more contained language, with clear ways to do thing (I guess I…

> Python was used as an example because people know Python and reader can compare it to something known. I don't think you understood the point I made. My point is that Python supports conditional expressions for years. Support for conditional expressions already means that in Python indeed "if is just a function". Therefore, the whole premise of the article is null and void, and the article is thus pointless. This i…

If Python has special syntax for `if` and so makes if an expression, it doesn't mean that `if` is a function.

If `if` is a function why don't you call it like other functions in Python?

    if( .... )
Functions are first class in Python now AFAIK. Can you assign `if` to a variable?

Also, blog-posts is not just about `if`, is `for` a function in Python, `def`, `return`, `class`?

Re: When if is just a function

#84
post #10
post #7

Is this just a quirk in my display, or are all the code blocks in this formatted like a CIA black highlighter

I checked in Firefox and Chrome (on Linux) and code samples look OK to me. What browser/OS are you using. Maybe send me a screenshot at janko dot itm at gmail.

This is on FF for me. Specifically Zen, which is FF based.

Re: When if is just a function

#85
post #82
post #74

Earlier quoted context omitted.

No instance for (Eq (MyBool a0 -> a0 -> a0 -> a0)) arising from a use of ‘==’ Undecidability of function equality aside, we could indeed define "myIf = id" instead.

Fair point, though if I remeber correctly there is only one function with type a->a and so we get equality automatically. (This may be untrue in the presence of the likes of unsafeCoerce.)

There are other functions MyBool a -> MyBool a, such as not = \b x y -> b y x.

Re: When if is just a function

#86
post #84
post #10

Earlier quoted context omitted.

I checked in Firefox and Chrome (on Linux) and code samples look OK to me. What browser/OS are you using. Maybe send me a screenshot at janko dot itm at gmail.

This is on FF for me. Specifically Zen, which is FF based.

You still have this problem? I tested and fixed css yesterday. What exactly is problematic?

Re: When if is just a function

#87
post #54

For lambda calculus, the motto is "when everything is a function". The boolean true is the function λx.λy.x, while false is λx.λy.y. If b then x else y then simply becomes b x y. In a functional language like Haskell that is basically a typed lambda calculus with lots of syntactic sugar, we can replicate this with: type MyBool a = a -> a -> a myTrue :: MyBool a myTrue = \x y -> x myFalse :: MyBool a myFalse = \x y ->…

This is https://en.wikipedia.org/wiki/Church_encoding#Church_Boolean...

But there are other encodings

Re: When if is just a function

#88
post #54

For lambda calculus, the motto is "when everything is a function". The boolean true is the function λx.λy.x, while false is λx.λy.y. If b then x else y then simply becomes b x y. In a functional language like Haskell that is basically a typed lambda calculus with lots of syntactic sugar, we can replicate this with: type MyBool a = a -> a -> a myTrue :: MyBool a myTrue = \x y -> x myFalse :: MyBool a myFalse = \x y ->…

This is https://en.wikipedia.org/wiki/Church_encoding#Church_Boolean... But there are other encodings

This is both the Church encoding and the Scott encoding of the abstract data type

    data Bool = True | False
making it pretty much the only encoding you find in the literature.

This is quite different from the case of the natural numbers, where not only do the Church and Scott encoding differ, but there are several other reasonable representations fitting particular purposes.

Re: When if is just a function

#90
post #76

The Trade-offs section doesn't list the biggest one. Secretly, all code wants to be spaghetti. You and your team have to put a conscious effort into prevent that from happening. Degrading the core of the language like this is like inoculating your homebrew with sewage and expecting it not to go wrong.

That is sort of like saying all visual art projects want to become "the million dollar / pixel homepage" so providing an empty canvas and full color palete will just enable people to create visual sewage because nothing stops them from doing so. I never programmed in a team, so my experience of programming is probably very different from yours. You probably want something like electric cattle fencing (if I borrow you…

That analogy may not be suitable for this case because value proposition between the aesthetics vs the function is different for visual art projects compared to software. There is also the maintainability factor where most aged software (especially the closed source ones in private sector) change maintainers every few years. Old maintainers most often lose access to the source code and become unreachable after leaving their job.
Post reply on HN