How to implement "symmetrical non-strict" or "in Haskell"

I want to define a function that has the following properties

symmetricLazyOr :: Bool -> Bool -> Bool symmetricLazyOr True _|_ === True symmetricLazyOr _|_ True === True 

Otherwise, it works like a regular or .

Is this possible in Haskell?

UPDATE

This question focuses on semantic rather than detailing implementation. Intuitively, or must be symmetric, which means or ab === or ba for all given a and b . However, this is not true in Haskell, since or _|_ True === _|_ while or True _|_ === True .

+7
haskell
source share
1 answer

In other words, are you looking for a function that, given the two arguments, tries to evaluate them and is true if any argument is true? And, in particular, will the True result be returned if at least one True argument is not lower?

Assuming this is correct, it is possible, but not pure. To implement this, you need to split two threads to evaluate each of the branches. The unamb package has some functions for dealing with such cases (including parallel or por ). Another option is lvish , which should also work in this case when I understand it.

+14
source share

All Articles