Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

equivalent of ruby ...? in haskell

Tags:

haskell

naming

In ruby ? is allowed at the end of identifier which allows things like

if do_something? do_something

which allow to differientiate function returing a bool from function doing something.

In Haskell, obviously the type signature tells you the difference between those two function, but is there a name convention or naming pattern to name bool or options ?

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

the obvious code would be

generate options = do
     when (generateLabels? options) generateLabels

but as generateLabels? is not valid name, how can I call it ?

like image 511
mb14 Avatar asked Sep 05 '14 16:09

mb14


1 Answers

If you glance at the functions that return Bool, you'll notice that the convention is to use a predicate that when used in code reads like a sentence. For example:

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

In your function I'd suggest that you rename generateLables? to something like needsLabels as @bheklilr pointed out in order to make your code more readable.

like image 199
Mokosha Avatar answered Nov 10 '22 17:11

Mokosha