Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #340 #341

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Agda2Hs/Compile/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,20 @@ lambdaCase q ty args = compileLocal $ setCurrentRangeQ q $ do
cs <- mapMaybeM (compileClause' mname (Just q) (hsName "(lambdaCase)") ty') cs

case cs of
-- If there is a single clause and all patterns got erased, we
-- simply return the body. do
[Hs.Match _ _ [] (Hs.UnGuardedRhs _ rhs) _] -> return rhs
-- If there is a single clause and all proper patterns got erased,
-- we turn the remaining arguments into normal lambdas.
[Hs.Match _ _ ps (Hs.UnGuardedRhs _ rhs) _]
| null ps -> return rhs
| all isVarPat ps -> return $ Hs.Lambda () ps rhs
_ -> do
lcase <- hsLCase =<< mapM clauseToAlt cs -- Pattern lambdas cannot have where blocks
eApp lcase <$> compileArgs ty' rest
-- undefined -- compileApp lcase (undefined, undefined, rest)

where
isVarPat :: Hs.Pat () -> Bool
isVarPat Hs.PVar{} = True
isVarPat _ = False

-- | Compile @if_then_else_@ to a Haskell @if ... then ... else ... @ expression.
ifThenElse :: DefCompileRule
Expand Down
2 changes: 2 additions & 0 deletions test/AllTests.agda
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import Issue305
import Issue302
import Issue309
import Issue317
import ErasedPatternLambda

{-# FOREIGN AGDA2HS
import Issue14
Expand Down Expand Up @@ -167,4 +168,5 @@ import Issue305
import Issue302
import Issue309
import Issue317
import ErasedPatternLambda
#-}
18 changes: 18 additions & 0 deletions test/ErasedPatternLambda.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
open import Haskell.Prelude

Scope = List Bool

data Telescope (@0 α : Scope) : @0 Scope → Set where
ExtendTel : ∀ {@0 x β} → Bool → Telescope (x ∷ α) β → Telescope α (x ∷ β)
{-# COMPILE AGDA2HS Telescope #-}

caseTelBind : ∀ {@0 x α β} (tel : Telescope α (x ∷ β))
→ ((a : Bool) (rest : Telescope (x ∷ α) β) → @0 tel ≡ ExtendTel a rest → d)
→ d
caseTelBind (ExtendTel a tel) f = f a tel refl

{-# COMPILE AGDA2HS caseTelBind #-}

checkSubst : ∀ {@0 x α β} (t : Telescope α (x ∷ β)) → Bool
checkSubst t = caseTelBind t λ ty rest → λ where refl → True
{-# COMPILE AGDA2HS checkSubst #-}
1 change: 1 addition & 0 deletions test/golden/AllTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ import Issue305
import Issue302
import Issue309
import Issue317
import ErasedPatternLambda

10 changes: 10 additions & 0 deletions test/golden/ErasedPatternLambda.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module ErasedPatternLambda where

data Telescope = ExtendTel Bool Telescope

caseTelBind :: Telescope -> (Bool -> Telescope -> d) -> d
caseTelBind (ExtendTel a tel) f = f a tel

checkSubst :: Telescope -> Bool
checkSubst t = caseTelBind t (\ ty rest -> True)

Loading