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

Add a primitive Let that is compiled to let in Haskell #252

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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
Loading