I’m having trouble understanding what you mean by an option type that is not a monad.
I thought the value of an option type was being able to “program the semicolon” to do automatic null checks for you.
I thought the value of an option type was being able to “program the semicolon” to do automatic null checks for you.
datatype 'a option = None | Some of 'a data Maybe a = Nothing | Just a
deriving ( Eq, Ord )
And the deriving line isn't really nessasary.The Monad module is larger and contains code specific to Maybe [1]:
instance Monad Maybe where
(Just x) >>= k = k x
Nothing >>= _ = Nothing
(>>) = (*>)
fail _ = Nothing
(Only the first 2 lines are needed. The 3rd is an optimization, the 4th is a historical wart that will be removed in future versions (moved to MonadFail)[0] https://hackage.haskell.org/package/base-4.12.0.0/docs/src/G...
[1] https://hackage.haskell.org/package/base-4.12.0.0/docs/src/G...
In the context of strict, statically typed language an algebraic Option type is good-enough.
Many algebraic data types are monads. I’m not sure why you think that is a contradiction.