The equivalent of a ruby ​​...? in haskell

In ruby? allowed at the end of the identifier, allowing things like

if do_something? do_something

which allow you to differentiate a function while keeping the bool from a function that does something.

In Haskell, it is obvious that a type signature tells you the difference between the two functions, but is there a naming convention or naming pattern for the bool name or parameters?

In my case, I want to generate (or not) some labels depending on the value of the parameters (passed as an argument).

obvious code will be

 generate options = do when (generateLabels? options) generateLabels 

but how to generateLabels? Invalid name, how can I call it?

+6
source share
1 answer

If you look at the functions that Bool returns , you will notice that the convention is to use a predicate, which when used in code reads as a sentence. For instance:

 isDenormalized :: RealFloat a => a -> Bool isSigned :: Bits a => a -> Bool isAlphaNum :: Char -> Bool 

In your function, I suggest you rename generateLables? into something like needsLabels , as @bheklilr pointed out, to make your code more readable.

+6
source

Source: https://habr.com/ru/post/974892/


All Articles