Skip to content

Commit

Permalink
Add a primitive Let that is compiled to let in Haskell
Browse files Browse the repository at this point in the history
  • Loading branch information
jespercockx committed Dec 11, 2023
1 parent 707c9a6 commit ecccab6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Haskell/Prim.agda
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ if_then_else_ : {@0 a : Set ℓ} → (flg : Bool) → (@0 {{ flg ≡ True }} →
if False then x else y = y
if True then x else y = x

Let : a (a b) b
Let x f = f x

--------------------------------------------------
-- Agda strings

Expand Down
7 changes: 7 additions & 0 deletions src/Agda2Hs/Compile/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ isSpecialTerm q = case prettyShow q of
"Haskell.Prim.Enum.Enum.enumFromThen" -> Just mkEnumFromThen
"Haskell.Prim.Enum.Enum.enumFromThenTo" -> Just mkEnumFromThenTo
"Haskell.Prim.case_of_" -> Just caseOf
"Haskell.Prim.Let" -> Just hsLet
"Haskell.Prim.Monad.Do.Monad._>>=_" -> Just bind
"Haskell.Prim.Monad.Do.Monad._>>_" -> Just sequ
"Agda.Builtin.FromNat.Number.fromNat" -> Just fromNat
Expand Down Expand Up @@ -172,6 +173,12 @@ caseOf _ es = compileElims es >>= \case
-- applied to non-lambda / partially applied
_ -> genericError $ "case_of_ must be fully applied to a lambda"

hsLet :: QName -> Elims -> C (Hs.Exp ())
hsLet _ es = compileElims es >>= \case
v : (Hs.Lambda _ [Hs.PVar () p] body) : [] -> do
return $ Hs.Let () (Hs.BDecls () [Hs.FunBind () [Hs.Match () p [] (Hs.UnGuardedRhs () v) Nothing]]) body
_ -> genericError $ "Let must be fully applied to a lambda"

lambdaCase :: QName -> Elims -> C (Hs.Exp ())
lambdaCase q es = setCurrentRangeQ q $ do
Function{funClauses = cls, funExtLam = Just ExtLamInfo {extLamModule = mname}}
Expand Down

0 comments on commit ecccab6

Please sign in to comment.