7
User
Recs.
Recs.
4
Updates
Last
Updated
Updated
Activity
9 Options
Haskell has no shorthand ternary operator. The built-'in' 'if'-'then'-'else' is always ternary, and is an expression (imperative languages tend to have '?:'=expression, 'if'=statement). If you want, though,
True ? x = const x
False ? _ = id
will define (?) to be the ternary operator:
(a ? b $ c) == (if a then b else c)
You'd have to resort to macros in most other languages to define your own short-circuiting logical operators, but Haskell is a fully lazy language, so it just works.
-- prints "I'm alive! :)"
main = True ? putStrLn "I'm alive! :)" $ error "I'm dead :("
Specs
Pros
Know any positive aspects of this option?
Cons
Know any negative aspects of this option?
Recommendations
User-defined control structures
Recommended 11 years ago
Robert hasn’t added their experience, pros or cons to their recommendation.
User-defined control structures
Recommended 11 years ago
Riyad hasn’t added their experience, pros or cons to their recommendation.
User-defined control structures
Recommended 11 years ago
Austin hasn’t added their experience, pros or cons to their recommendation.
User-defined control structures
Recommended 11 years ago
etler hasn’t added their experience, pros or cons to their recommendation.
User-defined control structures
Recommended 11 years ago
Owen hasn’t added their experience, pros or cons to their recommendation.
User-defined control structures
Recommended 11 years ago
Stuart hasn’t added their experience, pros or cons to their recommendation.
User-defined control structures
Recommended 11 years ago
T-R hasn’t added their experience, pros or cons to their recommendation.