Skip to content

Commit 17e4b6e

Browse files
committed
eta-functions-expl typechecks when using Church equality
1 parent e6eded9 commit 17e4b6e

File tree

4 files changed

+25
-63
lines changed

4 files changed

+25
-63
lines changed

app/Agda/Core/ToCore.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import Agda.Compiler.Backend (Definition(defType))
4848
import Control.Exception (throw)
4949

5050
import Debug.Trace
51+
import Agda.TypeChecking.Pretty (PrettyTCM(prettyTCM))
5152

5253

5354
-- TODO(flupe): move this to Agda.Core.Syntax
@@ -137,9 +138,7 @@ instance ToCore I.Term where
137138
toCore (I.Lit l) = throwError "literals not supported"
138139

139140
-- (diode-lang) Seems like a bug: lookUpDefOrData can return data, but a `TDef` is always constructed
140-
-- toCore (I.Def qn es) = tApp <$> (TDef <$> lookupDefOrData qn) <*> toCore es
141-
142-
141+
143142
toCore (I.Def qn es) = do
144143
coreEs <- toCore es
145144
-- Try looking up as definition first
@@ -257,7 +256,7 @@ toCoreDefn (I.FunctionDefn def) _ =
257256
, vars <- I.clausePats cl
258257
, Just body <- I.clauseBody cl
259258
-- -> Core.FunctionDefn <$> toCore body
260-
-> throwError "only definitions via λ are supported"
259+
-> trace ("matched on I.FunctionData with vars=" <> (show (I.clausePats cl))) (throwError "only definitions via λ are supported")
261260

262261
-- case with pattern matching variables
263262
I.FunctionData{..}
@@ -268,7 +267,7 @@ toCoreDefn (I.FunctionDefn def) _ =
268267
| isJust (maybeRight _funProjection >>= I.projProper) -- record projections case
269268
-> throwError "record projections aren't supported"
270269
I.FunctionData{}
271-
-> throwError "unsupported case (shouldn't happens)"
270+
-> throwError "unsupported case (shouldn't happen)"
272271

273272
toCoreDefn (I.DatatypeDefn dt) ty =
274273
withError (\e -> multiLineText $ "datatype definition failure: \n" <> Pretty.render (nest 1 e)) $ do
@@ -349,6 +348,7 @@ instance ToCore a => ToCore (Arg a) where
349348
-- TODO(flupe): enforce that there are no weird modalities in the arg (e.g: disallow irrelevance)
350349
instance ToCore a => ToCore (I.Dom a) where
351350
type CoreOf (I.Dom a) = CoreOf a
351+
toCore :: ToCore a => I.Dom a -> ToCoreM (CoreOf (I.Dom a))
352352
toCore = toCore . unDom
353353

354354

app/Main.hs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@ agdaCorePreModule _ _ tlm _ =
188188
type ACSyntax = Either String Core.Definition
189189

190190

191-
debugIndex :: Index -> TCM ()
192-
debugIndex index = do
193-
let indexAsNat = indexToNat index
194-
reportSDoc "agda-core.debug" 10 $ text ("Index of definition being translated: " <> show indexAsNat)
195-
reportSDoc "agda-core.debug" 10 $ text ""
196-
197191
agdaCoreCompile :: ACEnv -> ACMEnv -> IsMain -> Internal.Definition -> TCM ACSyntax
198192
agdaCoreCompile env _ _ def = do
199193
let ACEnv{toCoreGlobal = ioTcg, toCoreCounterID = ioIndex, toCoreNames = ioNames, toCorePreSignature = ioPreSig } = env
@@ -211,7 +205,6 @@ agdaCoreCompile env _ _ def = do
211205
-- if a constructor is encontered, skip it to avoid conflict
212206
(ntcg, nnames) <- case theDef of
213207
Internal.Datatype{dataCons} -> do
214-
reportSDoc "agda-core.check" 10 $ text $ "Adding all constructors of datatype " <> name <> " to tcg environment"
215208
let ntcg_datas = Map.insert defName index tcg_datas
216209
nnames_datas = Map.insert (indexToNat index) name nameData
217210
tcg_data_cons = Map.fromList (zip dataCons (map (index,) (iterate Suc Zero)))
@@ -247,7 +240,8 @@ agdaCoreCompile env _ _ def = do
247240
reportSDoc "agda-core.check" 4 $ text $ " Type: " <> prettyCore nnames ty'
248241
reportSDoc "agda-core.check" 4 $ text $ " Definition: " <> prettyCore nnames defn'
249242

250-
debugIndex index
243+
reportSDoc "agda-core.debug" 10 $ text ("Index of definition being translated: " <> show (indexToNat index))
244+
reportSDoc "agda-core.debug" 10 $ text ""
251245

252246
case defn' of
253247
Core.FunctionDefn _ -> liftIO $ writeIORef ioPreSig $

test/EtaFunctions.agda

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ data Nat : Set where
88
zero : Nat
99
suc : Nat → Nat
1010

11-
-- data _≡_ {A : Set} (x : A) : A → Set where
12-
-- refl : x ≡ x
11+
--data _≡_ {A : Set} (x : A) : A → Set where
12+
-- refl : x ≡ x
13+
14+
--postulate
15+
-- _≡_ : {A : Set} (x : A) → A → Set
16+
-- refl : {A : Set} {x : A} → x ≡ x
17+
18+
Id : (A : Set) (x : A) → A → Set₁
19+
Id = λ A x y → (P : A → Set) → P x → P y
20+
21+
refl : (A : Set) (x : A) → Id A x x
22+
refl = λ A x P p → p
1323

1424
id_typ : Set → Set
1525
id_typ = λ A → A
@@ -35,11 +45,14 @@ f = addTwo
3545
g : Nat → Nat
3646
g = λ x → addTwo x
3747

48+
z : (A B : Set) (f : A → B) → A → B
49+
z = λ (A B : Set) h → λ a → (h a)
50+
3851
-- eta-functions : {A B : Set} (f : A → B) → (f ≡ (λ x → f x))
39-
-- eta-functions = λ f → refl
52+
-- eta-functions = λ h → refl
4053

41-
-- eta-functions_expl : (A B : Set) (f : A → B) → (f ≡ (λ x → f x))
42-
-- eta-functions_expl = λ A B → λ f → refl
54+
eta-functions_expl : (A B : Set) (f : A → B) → (Id (A → B) f (λ x → f x))
55+
eta-functions_expl = λ A B → λ f → refl (A → B) f
4356

4457
-- test : (A B : Set) (f : A → B) → Set
4558
-- test = λ A B → λ f → A

test/EtaFunctionsNoCrash.agda

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)