Skip to content

Commit

Permalink
Add support for code auto-generation of records with non-dependent fu…
Browse files Browse the repository at this point in the history
…nction fields
  • Loading branch information
javierdiaz72 committed Dec 17, 2024
1 parent a482527 commit 5dc3eeb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/agda-spec/src/Foreign/HaskellTypes/Deriving.agda
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ private
renderHsType (def (quote Pair) (_ ∷ _ ∷ vArg a ∷ vArg b ∷ [])) = printf "(%s, %s)" (renderHsType a) (renderHsType b)
renderHsType (def d []) = renderHsTypeName d
renderHsType (def d vs) = printf "(%s %s)" (renderHsTypeName d) (joinStrings " " (renderHsArgs vs))
renderHsType (Π[ s ∶ arg _ a ] b) = printf "%s -> %s" (renderHsType a) (renderHsType b)
renderHsType t = printf "(TODO: renderHsType %s)" (show t)

renderHsArgs [] = []
Expand Down Expand Up @@ -269,14 +270,17 @@ private
(showName d) con

hsImports : String
hsImports = "import GHC.Generics (Generic)"
hsImports = "import GHC.Generics (Generic)\nimport Text.Show.Functions\n"

hsInstances : String
hsInstances = "instance Eq (a -> b) where _ == _ = False\n" -- functions are never equal

-- Take the name of a simple data type and generate the COMPILE and
-- FOREIGN pragmas to bind to Haskell.
bindHsType : NameEnv Name Name TC ⊤
bindHsType env agdaName hsName = getDefinition hsName >>= λ where
(data-type pars cs) do
pragmaForeign "GHC" hsImports
pragmaForeign "GHC" (hsImports & "\n" & hsInstances)
pragmaCompile "GHC" hsName $ compilePragma hsName cs
getDefinition agdaName >>= λ where
(data-type _ _) pragmaForeign "GHC" =<< foreignPragma hsName cs
Expand Down

0 comments on commit 5dc3eeb

Please sign in to comment.