lean4-htt/library/init/meta/pexpr.lean
Sebastian Ullrich 0aacccd8c9 feat(frontends/lean): change structure update notation
`{s with ...}` is now `{..., ..s}`, which more clearly expresses that the
result type is not necessarily equal to the type of `s` (in absence of an
expected type and a structure name, we still default to the type of `s`).

Multiple fallback sources can be given: `{..., ..s, ..t}` will fall back to
searching a field in `s`, then in `t`. The last component can also be `..`,
which will replace any missing fields with a placeholder.

The old notation will be removed in the future.
2017-11-17 16:40:47 -08:00

46 lines
1.5 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.expr
universe u
/-- Quoted expressions. They can be converted into expressions by using a tactic. -/
@[reducible] meta def pexpr := expr ff
protected meta constant pexpr.of_expr : expr → pexpr
meta constant pexpr.is_placeholder : pexpr → bool
meta constant pexpr.mk_placeholder : pexpr
meta constant pexpr.mk_field_macro : pexpr → name → pexpr
meta constant pexpr.mk_explicit : pexpr → pexpr
/-- Choice macros are used to implement overloading. -/
meta constant pexpr.is_choice_macro : pexpr → bool
/-- Information about unelaborated structure instance expressions. -/
meta structure structure_instance_info :=
(struct : option name := none)
(field_names : list name)
(field_values : list pexpr)
(sources : list pexpr := [])
/-- Create a structure instance expression. -/
meta constant pexpr.mk_structure_instance : structure_instance_info → pexpr
meta constant pexpr.get_structure_instance_info : pexpr → option structure_instance_info
meta class has_to_pexpr (α : Sort u) :=
(to_pexpr : α → pexpr)
meta def to_pexpr {α : Sort u} [has_to_pexpr α] : α → pexpr :=
has_to_pexpr.to_pexpr
meta instance : has_to_pexpr pexpr :=
⟨id⟩
meta instance : has_to_pexpr expr :=
⟨pexpr.of_expr⟩
meta instance (α : Sort u) (a : α) : has_to_pexpr (reflected a) :=
⟨pexpr.of_expr ∘ reflected.to_expr⟩