@@ -52,6 +52,23 @@ when False f = pure ()
53||| Fold using Alternative
53||| Fold using Alternative
55+||| If you have a left-biased alternative operator `<|>`, then `choice`
56+||| performs left-biased choice from a list of alternatives, which means that
57+||| it evaluates to the left-most non-`empty` alternative.
59+||| If the list is empty, or all values in it are `empty`, then it
60+||| evaluates to `empty`.
65+||| -- given a parser expression like:
66+||| expr = literal <|> keyword <|> funcall
68+||| -- choice lets you write this as:
69+||| expr = choice [literal, keyword, funcall]
55−||| This is called `asum` in Haskell.
72+||| Note: In Haskell, `choice` is called `asum`.
56choice : (Foldable t, Alternative f) => t (f a) -> f a
73choice : (Foldable t, Alternative f) => t (f a) -> f a
57choice x = foldr (<|>) empty x
74choice x = foldr (<|>) empty x