Hidden features of Haskell [closed]

User-defined control structures

Haskell has no shorthand ternary operator. The built-in ifthenelse 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 :("

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)