fork download
  1. class BoolLike a where
  2. isTrue :: a -> Bool
  3.  
  4. instance BoolLike Bool where
  5. isTrue = id
  6.  
  7. instance BoolLike [a] where
  8. isTrue = not . null
  9.  
  10. (&.&) :: BoolLike a => a -> a -> a
  11. x &.& y
  12. | isTrue x = y
  13. | otherwise = x
  14.  
  15. (|.|) :: BoolLike a => a -> a -> a
  16. x |.| y
  17. | isTrue x = x
  18. | otherwise = y
  19.  
  20. main = do
  21. print $ [] |.| [1, 2 ,3]
  22. print $ [] &.& [1, 2 ,3]
  23.  
Success #stdin #stdout 0s 6224KB
stdin
Standard input is empty
stdout
[1,2,3]
[]