Skip to content

Commit b63f7f3

Browse files
committed
Small refactor + new test
Rather than trying to extract the dot pattern name with nameOf, we make use of the PatOrigin in PatternInfo
1 parent 293b30c commit b63f7f3

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

src/Agda2Hs/Compile/Function.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Agda.Utils.Size ( Sized(size) )
3737

3838
import Agda2Hs.AgdaUtils
3939
import Agda2Hs.Compile.Name ( compileQName )
40-
import Agda2Hs.Compile.Term ( compileTerm, usableDom, dependentDom, extractMaybeName )
40+
import Agda2Hs.Compile.Term ( compileTerm, usableDom, dependentDom )
4141
import Agda2Hs.Compile.Type ( compileType, compileDom, DomOutput(..), compileDomType )
4242
import Agda2Hs.Compile.TypeDefinition ( compileTypeDef )
4343
import Agda2Hs.Compile.Types
@@ -294,8 +294,7 @@ compilePats ty ((namedArg -> ProjP po pn):ps) = do
294294

295295
compilePats (absBody b) ps
296296

297-
compilePats ty (p:ps) = do
298-
let pat = namedArg p
297+
compilePats ty ((namedArg -> pat):ps) = do
299298
(a, b) <- mustBePi ty
300299
reportSDoc "agda2hs.compile.pattern" 10 $ text "Compiling pattern:" <+> prettyTCM pat
301300
let rest = compilePats (absApp b (patternToTerm pat)) ps
@@ -305,21 +304,21 @@ compilePats ty (p:ps) = do
305304
DOType -> rest
306305
DOTerm -> do
307306
checkNoAsPatterns pat
308-
(:) <$> compilePat (unDom a) (extractMaybeName p) pat <*> rest
307+
(:) <$> compilePat (unDom a) pat <*> rest
309308

310309

311-
compilePat :: Type -> Maybe ArgName -> DeBruijnPattern -> C (Hs.Pat ())
310+
compilePat :: Type -> DeBruijnPattern -> C (Hs.Pat ())
312311

313312
-- variable pattern
314-
compilePat ty _ p@(VarP o x)
313+
compilePat ty p@(VarP o x)
315314
| PatOWild <- patOrigin o = return $ Hs.PWildCard ()
316315
| otherwise = do
317316
n <- hsName <$> compileDBVar (dbPatVarIndex x)
318317
checkValidVarName n
319318
return $ Hs.PVar () n
320319

321320
-- special constructor pattern
322-
compilePat ty _ (ConP ch i ps) = do
321+
compilePat ty (ConP ch i ps) = do
323322
Just ((_, _, _), ty) <- getConType ch =<< reduce ty
324323
let c = conName ch
325324

@@ -331,18 +330,19 @@ compilePat ty _ (ConP ch i ps) = do
331330
return $ pApp c ps
332331

333332
-- literal patterns
334-
compilePat ty _ (LitP _ l) = compileLitPat l
333+
compilePat ty (LitP _ l) = compileLitPat l
335334

336335
-- "Inferred" dot patterns that the programmer has explicitly named are
337336
-- compiled to variable patterns using that given name, wildcards otherwise
338-
compilePat _ (Just n) (DotP _ _) = do
339-
let n' = hsName n
337+
compilePat _ (DotP (PatternInfo (PatOVar n) _) _) = do
338+
let n' = hsName $ prettyShow n
340339
checkValidVarName n'
341340
return $ Hs.PVar () n'
342-
compilePat _ Nothing (DotP _ _) = return $ Hs.PWildCard ()
341+
compilePat _ (DotP (PatternInfo PatODot _) _) =
342+
return $ Hs.PWildCard ()
343343

344344
-- nothing else is supported
345-
compilePat _ _ p = agda2hsErrorM $ "bad pattern:" <?> prettyTCM p
345+
compilePat _ p = agda2hsErrorM $ "bad pattern:" <?> prettyTCM p
346346

347347

348348
compileErasedConP :: Type -> Strictness -> NAPs -> C (Hs.Pat ())

test/AllTests.agda

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import RuntimeCast
105105
import Issue306
106106
import RelevantDotPattern1
107107
import RelevantDotPattern2
108+
import RelevantDotPattern3
108109

109110
{-# FOREIGN AGDA2HS
110111
import Issue14
@@ -207,4 +208,5 @@ import RuntimeCast
207208
import Issue306
208209
import RelevantDotPattern1
209210
import RelevantDotPattern2
211+
import RelevantDotPattern3
210212
#-}

test/RelevantDotPattern3.agda

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Derived from "ErasedPatternLambda"
2+
open import Haskell.Prelude
3+
4+
Scope = List Bool
5+
6+
data Telescope (@0 α : Scope) : @0 Scope Type where
7+
ExtendTel : {@0 x β} Bool Telescope (x ∷ α) β Telescope α (x ∷ β)
8+
{-# COMPILE AGDA2HS Telescope #-}
9+
10+
caseTelBind : {@0 x α β} (tel : Telescope α (x ∷ β))
11+
((a : Bool) (rest : Telescope (x ∷ α) β) @0 tel ≡ ExtendTel a rest d)
12+
d
13+
caseTelBind (ExtendTel a tel) f = f a tel refl
14+
15+
{-# COMPILE AGDA2HS caseTelBind #-}
16+
17+
checkSubst' : {@0 x α β} (t : Telescope α (x ∷ β)) (ty : Bool) (rest : Telescope (x ∷ α) β) @0 t ≡ ExtendTel ty rest Bool
18+
checkSubst' (ExtendTel ty' rest') ty rest refl = True
19+
{-# COMPILE AGDA2HS checkSubst' #-}
20+
21+
checkSubst : {@0 x α β} (t : Telescope α (x ∷ β)) Bool
22+
checkSubst t = caseTelBind t (checkSubst' t)
23+
{-# COMPILE AGDA2HS checkSubst #-}

test/golden/AllTests.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ import RuntimeCast
100100
import Issue306
101101
import RelevantDotPattern1
102102
import RelevantDotPattern2
103+
import RelevantDotPattern3
103104

test/golden/RelevantDotPattern3.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module RelevantDotPattern3 where
2+
3+
data Telescope = ExtendTel Bool Telescope
4+
5+
caseTelBind :: Telescope -> (Bool -> Telescope -> d) -> d
6+
caseTelBind (ExtendTel a tel) f = f a tel
7+
8+
checkSubst' :: Telescope -> Bool -> Telescope -> Bool
9+
checkSubst' (ExtendTel ty' rest') ty rest = True
10+
11+
checkSubst :: Telescope -> Bool
12+
checkSubst t = caseTelBind t (checkSubst' t)
13+

0 commit comments

Comments
 (0)