Ad
  • Custom User Avatar

    | b = x would be fine. Straight pattern matching is another possibility, but it's mostly a matter of taste.

    I wouldn't worry too much about any difference between case, if and | expressions and pattern matches. After desugaring, there's probably no appreciable difference anyway. I would be not at all surprised if most solutions generate exactly the same bytecode in the end.

  • Custom User Avatar

    That being said, learn the syntax first, how to interpret the error messages as best you can - write clean code later, you can always refactor.

  • Custom User Avatar

    Haskell is about expressions, guards are just IF blocks, in general

    
    boolValue = True
    if boolValue == True then "It is true" else "It is false"
    

    would normally just be

    
    boolValue = True
    if boolValue then "It is true" else "It is false"
    
  • Custom User Avatar

    Thanks for the feedback! I was using Codewars to help learn Haskell so I'm not surprised my solution isn't great. Is | b = x valid or do you have another suggestion. Thanks again.

  • Custom User Avatar

    b == True is an antipattern.