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 #213] Properly deal with unboxed records, again #214

Merged
merged 1 commit into from
Nov 7, 2023
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
8 changes: 5 additions & 3 deletions src/Agda2Hs/Compile/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Agda2Hs.Compile.Type where
import Control.Arrow ( (>>>) )
import Control.Monad ( forM, when )
import Control.Monad.Reader ( asks )
import Data.List ( find )
import Data.Maybe ( mapMaybe )

import qualified Language.Haskell.Exts.Syntax as Hs
Expand Down Expand Up @@ -152,9 +153,10 @@ compileTypeArgs args = mapM (compileType . unArg) $ filter keepArg args
compileUnboxType :: QName -> Args -> C (Hs.Type ())
compileUnboxType r pars = do
def <- theDef <$> getConstInfo r
case recTel def `apply` pars of
EmptyTel -> __IMPOSSIBLE__
(ExtendTel a _) -> compileType $ unEl $ unDom a
let tel = telToList $ recTel def `apply` pars
case find keepArg tel of
Nothing -> __IMPOSSIBLE__
Just t -> compileType $ unEl $ snd (unDom t)

compileTransparentType :: Args -> C (Hs.Type ())
compileTransparentType args = compileTypeArgs args >>= \case
Expand Down
28 changes: 20 additions & 8 deletions test/UnboxPragma.agda
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

open import Haskell.Prelude

record ∃ (A : Set) (P : A → Set) : Set where
record ∃ (A : Set) (@0 P : A → Set) : Set where
constructor _[_]
field
el : A
Expand All @@ -10,13 +10,6 @@ open ∃ public

{-# COMPILE AGDA2HS ∃ unboxed #-}

record Σ0 (A : Set) (P : @0 A → Set) : Set where
field
@0 el : A
pf : P el

{-# COMPILE AGDA2HS Σ0 unboxed #-}

postulate
IsSorted : List Int → Set
looksfine : {xs : List Int} → IsSorted xs
Expand All @@ -41,3 +34,22 @@ sortAll : List (List Int)
sortAll = map el (map (λ xs → xs [ looksfine {xs} ]) ((1 ∷ 2 ∷ []) ∷ (3 ∷ []) ∷ []))

{-# COMPILE AGDA2HS sortAll #-}

record Σ0 (A : Set) (P : @0 A → Set) : Set where
constructor _[_]
field
@0 el : A
pf : P el
open Σ0 public

{-# COMPILE AGDA2HS Σ0 unboxed #-}

Scope : (name : Set) → Set
Scope name = Σ0 (List name) λ xs → ∃ Int λ n → length xs ≡ n

{-# COMPILE AGDA2HS Scope #-}

emptyScope : {name : Set} → Scope name
emptyScope = [] [ 0 [ refl ] ]

{-# COMPILE AGDA2HS emptyScope #-}
5 changes: 5 additions & 0 deletions test/golden/UnboxPragma.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ sort3 xs = xs
sortAll :: [[Int]]
sortAll = map (\ r -> r) (map (\ xs -> xs) [[1, 2], [3]])

type Scope name = Int

emptyScope :: Scope name
emptyScope = 0

Loading