What’s the point of ‘const’ in the Haskell Prelude?

It’s useful for passing to higher-order functions when you don’t need all their flexibility. For example, the monadic sequence operator >> can be defined in terms of the monadic bind operator as

x >> y = x >>= const y

It’s somewhat neater than using a lambda

x >> y = x >>= \_ -> y

and you can even use it point-free

(>>) = (. const) . (>>=)

although I don’t particularly recommend that in this case.

Leave a Comment

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