{"slug": "line-of-code-not-working-as-expected", "title": "Line of code not working as expected", "summary": "A Haskell beginner encountered unexpected behavior in a conditional expression due to operator precedence, where `x && y == False` was parsed as `x && (y == False)` instead of `(x && y) == False`. The fix was to parenthesize the conjunction, and the community also suggested using `not (x && y)` and removing redundant parentheses around string arguments to `print`.", "body_md": "i have a line of code which doesn’t work as i expect it too:\n\nparentspermission x y = if x && y == False then print(“no”) else print (“yes”)\n\nwhen i run parentspermission False False in ghci it gives me “yes” instead of “no” as it should be when false && false is false\n\nthis may not be worth mentioning but i am a beginner to haskell ive had some experience in python before and i am against using ai to learn haskell, i want to do it the old school way\n\na little addition is that when i ran parentspermission True False i got “no” as expected but when i ran parentspermission False True i somehow got “yes”\n\nCheck the precedences of `(&&)`\n\nand `(==)`\n\n. Neither function is magical in the language.\n\nmy understanding of this is the order i place && and ==, i would have usually placed a singlar equal sign after x && y but this isnt possible as a single equal sign is used to define functions.\n\nThe fix was to put x && y in parenthesis like so, (x && y) == False.\n\nNoting that you are new to Haskell, you do not need `( )`\n\naround the `\"no\"`\n\nand `\"yes\"`\n\nvalues. To apply a function `f :: a -> b`\n\nto `x :: a`\n\n, you write `f x`\n\n. Accordingly, you can write `print \"no\"`\n\n.\n\nAlso, here, if you want Haskell code to be presented nicely, you can put it between ‘fences’ (each on their own lines) before and after the code `~~~haskell`\n\n(opening fence) and `~~~`\n\n(closing fence). For example:\n\n``` php\nparentspermission :: Bool -> Bool -> IO ()\nparentspermission x y = if (x && y) == False then print “no” else print “yes”\n```\n\nA second also: `print \"no\"`\n\nis equivalent to `putStrLn (show \"no\")`\n\n. As `\"no\"`\n\nis a `String`\n\n, it may be that you do not actually want to output `show \"no\"`\n\nbut simply `\"no\"`\n\n. That is because:\n\n```\n> show \"no\" == \"\\\"no\\\"\"\nTrue\n```\n\n(where `\\\"`\n\nis an escaped double quote character in a Haskell string).\n\nI’d also add to this that I’d probably usually write `if not (x && y) then ... else ...`\n\ninstead of `(x && y) == False`\n\nin the conditional.\n\nEdit: Also, welcome to Haskell\n\nBuilding on [@slow-dive](/u/slow-dive) 's suggestion, there is a helpful (non-AI) tool named `hlint`\n\n:\n\nwhich can help you learn by thinking through its suggestions.\n\nFor example, if you put your code in a module:\n\n``` php\nmodule MyModule\n  ( parentspermission\n  ) where\n\nparentspermission :: Bool -> Bool -> IO ()\nparentspermission x y = if (x && y) == False then print (\"no\") else print (\"yes\")\n```\n\nand command `hlint MyModule`\n\n, it offers up (but in colour):\n\n```\nMyModule.hs:6:28-44: Suggestion: Redundant ==\nFound:\n  (x && y) == False\nPerhaps:\n  not (x && y)\n\nMyModule.hs:6:57-62: Warning: Redundant bracket\nFound:\n  (\"no\")\nPerhaps:\n  \"no\"\n\nMyModule.hs:6:75-81: Warning: Redundant bracket\nFound:\n  (\"yes\")\nPerhaps:\n  \"yes\"\n\n3 hints\n```\n\nThx i will check this out", "url": "https://wpnews.pro/news/line-of-code-not-working-as-expected", "canonical_source": "https://discourse.haskell.org/t/line-of-code-not-working-as-expected/14435#post_8", "published_at": "2026-07-20 10:34:14+00:00", "updated_at": "2026-07-20 13:04:57.352813+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Haskell", "hlint"], "alternates": {"html": "https://wpnews.pro/news/line-of-code-not-working-as-expected", "markdown": "https://wpnews.pro/news/line-of-code-not-working-as-expected.md", "text": "https://wpnews.pro/news/line-of-code-not-working-as-expected.txt", "jsonld": "https://wpnews.pro/news/line-of-code-not-working-as-expected.jsonld"}}