>>> complement (zeroBits :: Word) == (oneBits :: Word) True
>>> complement (oneBits :: Word) == (zeroBits :: Word) True
fail s >>= f = fail sIf your Monad is also MonadPlus, a popular definition is
fail _ = mzerofail s should be an action that runs in the monad itself, not an exception (except in instances of MonadIO). In particular, fail should not be implemented in terms of error.
>>> concat (Just [1, 2, 3]) [1,2,3]
>>> concat (Left 42) []
>>> concat [[1, 2, 3], [4, 5], [6], []] [1,2,3,4,5,6]
>>> concatMap (take 3) [[1..], [10..], [100..], [1000..]] [1,2,3,10,11,12,100,101,102,1000,1001,1002]
>>> concatMap (take 3) (Just [1..]) [1,2,3]
>>> const 42 "hello" 42
>>> map (const 42) [0..3] [42,42,42,42]
>>> mconcat ["Hello", " ", "Haskell", "!"] "Hello Haskell!"
partition p xs == (filter p xs, filter (not . p) xs)
>>> partition (`elem` "aeiou") "Hello World!" ("eoo","Hll Wrld!")
>>> permutations "abc" ["abc","bac","cba","bca","cab","acb"]The permutations function is maximally lazy: for each n, the value of permutations xs starts with those permutations that permute take n xs and keep drop n xs. This function is productive on infinite inputs:
>>> take 6 $ map (take 3) $ permutations ['a'..] ["abc","bac","cba","bca","cab","acb"]Note that the order of permutations is not lexicographic. It satisfies the following property:
map (take n) (take (product [1..n]) (permutations ([1..n] ++ undefined))) == permutations [1..n]
>>> sortOn fst [(2, "world"), (4, "!"), (1, "Hello")] [(1,"Hello"),(2,"world"),(4,"!")]The argument must be finite.