12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182{-# OPTIONS --safe --without-K #-}module Reflection.Utils.Core where open import Meta.Preludeopen import Meta.Init open import Data.Product using (map₁)open import Data.List using (map) import Reflection.AST.Abstraction as Absimport Reflection.AST.Argument as Arg -- ** basics absName : Abs A → StringabsName (abs s x) = s tyName : Type → Maybe NametyName = λ where (con n _) → just n (def n _) → just n _ → nothing -- ** alternative view of function types as a pair of a list of arguments and a return typeTypeView = List (Abs (Arg Type)) × Type viewTy : Type → TypeViewviewTy (Π[ s ∶ a ] ty) = map₁ ((abs s a) ∷_) (viewTy ty)viewTy ty = [] , ty tyView : TypeView → TypetyView ([] , ty) = tytyView (abs s a ∷ as , ty) = Π[ s ∶ a ] tyView (as , ty) argumentWise : (Type → Type) → Type → TypeargumentWise f ty = let as , r = viewTy ty as′ = map (Abs.map $ Arg.map f) as in tyView (as′ , r) viewTy′ : Type → Args Type × TypeviewTy′ (Π[ _ ∶ a ] ty) = map₁ (a ∷_) (viewTy′ ty)viewTy′ ty = [] , ty argTys : Type → Args TypeargTys = proj₁ ∘ viewTy′ resultTy : Type → TyperesultTy = proj₂ ∘ viewTy′ tyTele : Type → TelescopetyTele = λ where (Π[ s ∶ a ] ty) → (s , a) ∷ tyTele ty _ → [] -- ** definitions record DataDef : Set where field name : Name constructors : List (Name × TypeView) params : List (Abs (Arg Type)) indices : List (Abs (Arg Type)) record RecordDef : Set where field name : Name fields : List (Arg Name) params : List (Abs (Arg Type)) parameters : Definition → ℕparameters (data-type pars _) = parsparameters _ = 0 -- ** telescopes toTelescope : List (Abs (Arg Type)) → TelescopetoTelescope = map (λ where (abs n x) → (n , x)) fromTelescope : Telescope → List (Abs (Arg Type))fromTelescope = map (λ where (n , x) → (abs n x))