Is there anyway to define a function like the following in Haskell?
or True True = True
or True undefined = True
or True False = True
or undefined True = True
or undefined False = undefined
or undefined undefined = undefined
or False True = True
or False undefined = undefined
or False False = False
I don’t currently have a use case for it (though I’d be interested in one), I’m just interested if it’s possible.
Depending on your evaluation order (the order in which you inspect values) you can write a lazy version:
in fact, the default definition in Haskell will behave like this, since Haskell is a lazy language.
However, there’s no way to “skip” an undefined value, without looking at the value first, which will evaluate it to a bottom, which causes your expression to be undefined.
Remember that lazy values are presents with ghosts inside them:
If you look inside the box, a ghost might get you.
If checking for bottoms is important (e.g. as part of a testsuite) you can treat them as exceptions, and intercept them. But you wouldn’t do that in a pure function.