lean4-htt/library/init/alternative.lean
Sebastian Ullrich fd2c42a8bf chore(library, tests): switch to new attribute declaration syntax
sed -Ei 's/^(\s*)((private |protected )?(noncomputable )?(abbreviation|definition|meta_definition|theorem|lemma|proposition|corollary)\s+\S+\s*)((\s*\[(\S+(\s+[0-9]+)*|priority.*)\])+)\s*/\1attribute \6\n\1\2/' library/**/*.lean tests/**/*.lean
sed -Ei 's/\s+$//' library/**/*.lean  # remove trailing whitespace
2016-08-12 15:36:12 -07:00

25 lines
778 B
Text

/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import init.logic init.applicative
structure alternative [class] (f : Type → Type) extends applicative f :=
(failure : Π {A : Type}, f A)
(orelse : Π {A : Type}, f A → f A → f A)
attribute [inline]
definition failure {f : Type → Type} [alternative f] {A : Type} : f A :=
alternative.failure f
attribute [inline]
definition orelse {f : Type → Type} [alternative f] {A : Type} : f A → f A → f A :=
alternative.orelse
infixr ` <|> `:2 := orelse
attribute [inline]
definition guard {f : Type₁ → Type} [alternative f] (p : Prop) [decidable p] : f unit :=
if p then pure () else failure