{"action":"created","issue":{"url":"https://api.github.com/repos/elm-lang/core/issues/495","repository_url":"https://api.github.com/repos/elm-lang/core","labels_url":"https://api.github.com/repos/elm-lang/core/issues/495/labels{/name}","comments_url":"https://api.github.com/repos/elm-lang/core/issues/495/comments","events_url":"https://api.github.com/repos/elm-lang/core/issues/495/events","html_url":"https://github.com/elm-lang/core/issues/495","id":129959486,"number":495,"title":"(||) and (&&) not short-circuiting","user":{"login":"jvoigtlaender","id":5853832,"avatar_url":"https://avatars.githubusercontent.com/u/5853832?v=3","gravatar_id":"","url":"https://api.github.com/users/jvoigtlaender","html_url":"https://github.com/jvoigtlaender","followers_url":"https://api.github.com/users/jvoigtlaender/followers","following_url":"https://api.github.com/users/jvoigtlaender/following{/other_user}","gists_url":"https://api.github.com/users/jvoigtlaender/gists{/gist_id}","starred_url":"https://api.github.com/users/jvoigtlaender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvoigtlaender/subscriptions","organizations_url":"https://api.github.com/users/jvoigtlaender/orgs","repos_url":"https://api.github.com/users/jvoigtlaender/repos","events_url":"https://api.github.com/users/jvoigtlaender/events{/privacy}","received_events_url":"https://api.github.com/users/jvoigtlaender/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2016-01-30T08:47:28Z","updated_at":"2016-05-11T06:28:17Z","closed_at":"2016-05-11T00:27:57Z","body":"One might expect that there is no difference in behavior between this program:\r\n```elm\r\nimport Graphics.Element\r\n\r\nfib n = if n < 2 then 1 else fib (n-1) + fib (n-2)\r\n\r\nmain = Graphics.Element.show (True || fib 100 > 0)\r\n```\r\nand this program:\r\n```elm\r\nimport Graphics.Element\r\n\r\nfib n = if n < 2 then 1 else fib (n-1) + fib (n-2)\r\n\r\nmain = Graphics.Element.show ((||) True (fib 100 > 0))\r\n```\r\nBut there is. The first program shows a result immediately, whereas the second program goes into a near-endless computation (the browser complains and wants to stop the script).\r\n\r\nAn analogous problem exists for `(&&)`.\r\n\r\nI think the documentation should warn about that. Maybe at several places (the syntax guide, when talking about operators; the `core` documentation).\r\n\r\nIt might even be worth considering to remove `Basics.(||)` and `Basics.(&&)` altogether, and only leave the `||` and `&&` in as pieces that the compiler treats specially. (Apparently the compiler currently does treat them specially? Or how else is it explained that the expression `True || fib 100 > 0` does *not* fire off that expensive `fib 100` call?)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/elm-lang/core/issues/comments/218373154","html_url":"https://github.com/elm-lang/core/issues/495#issuecomment-218373154","issue_url":"https://api.github.com/repos/elm-lang/core/issues/495","id":218373154,"user":{"login":"jvoigtlaender","id":5853832,"avatar_url":"https://avatars.githubusercontent.com/u/5853832?v=3","gravatar_id":"","url":"https://api.github.com/users/jvoigtlaender","html_url":"https://github.com/jvoigtlaender","followers_url":"https://api.github.com/users/jvoigtlaender/followers","following_url":"https://api.github.com/users/jvoigtlaender/following{/other_user}","gists_url":"https://api.github.com/users/jvoigtlaender/gists{/gist_id}","starred_url":"https://api.github.com/users/jvoigtlaender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvoigtlaender/subscriptions","organizations_url":"https://api.github.com/users/jvoigtlaender/orgs","repos_url":"https://api.github.com/users/jvoigtlaender/repos","events_url":"https://api.github.com/users/jvoigtlaender/events{/privacy}","received_events_url":"https://api.github.com/users/jvoigtlaender/received_events","type":"User","site_admin":false},"created_at":"2016-05-11T06:28:17Z","updated_at":"2016-05-11T06:28:17Z","body":"But maybe at least a heads up in the documentation in `Basics` would be in order? That documentation currently reads like this:\r\n\r\n> ```elm\r\n> (&&) : Bool -> Bool -> Bool\r\n> ```\r\n> The logical AND operator. `True` if both inputs are `True`. This operator short-circuits to `False` if the first argument is `False`.\r\n\r\nIt says \"this operator\", and above that it is written \"`(&&)`\". So that's \"this operator\", right? Someone learning Elm has no reason to not assume from this that `(&&) False exp` will short-circuit. Or that passing \"the operator\" `(&&)` to another function will still provide short-circuiting. In your reply above you make a difference between operators and functions, and are of course correct about it, but people learning Elm will not necessarily be aware of this distinction, and specifically not here, where \"this operator\" refers to `(&&)` - which in your reply isn't actually the operator but the function.\r\n\r\nI haven't made this problem up. It originally came up in a student's code. I can elaborate on what the problem was and why none of the current language and `core` documentation addressed it. But maybe I'll instead first make a more modest documentation change proposal than what I started this issue with. Maybe you'll like that proposal without further ado. Maybe not.\r\n\r\nI propose to change the documentation to:\r\n> ```elm\r\n> (&&) : Bool -> Bool -> Bool\r\n> ```\r\n> The logical AND operator. `True` if both inputs are `True`. This operator, when used infix, short-circuits to `False` if the first argument is `False`.\r\n\r\nSo only adding the words \"when used infix\".\r\n\r\n"}}