Skip to content

Commit

Permalink
add Extra.Sigma
Browse files Browse the repository at this point in the history
  • Loading branch information
flupe authored and omelkonian committed Feb 22, 2024
1 parent e947207 commit 68eab23
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/Haskell/Extra/Sigma.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Haskell.Extra.Sigma where

record Σ (a : Set) (b : @0 a Set) : Set where
constructor _,_
field
fst : a
snd : b fst
open Σ public

infix 2 Σ-syntax

Σ-syntax : (a : Set) (@0 a Set) Set
Σ-syntax = Σ
{-# COMPILE AGDA2HS Σ-syntax inline #-}

syntax Σ-syntax a (λ x b) = Σ[ x ∈ a ] b
1 change: 1 addition & 0 deletions src/Agda2Hs/Compile/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ isSpecialCon :: QName -> Maybe ConCompileRule
isSpecialCon = prettyShow >>> \case
"Haskell.Prim.Tuple._,_" -> Just tupleTerm
"Haskell.Prim.Tuple._×_×_._,_,_" -> Just tupleTerm
"Haskell.Extra.Sigma._,_" -> Just tupleTerm
"Haskell.Extra.Erase.Erased" -> Just erasedTerm
"Haskell.Extra.Delay.Delay.now" -> Just compileErasedApp
"Haskell.Extra.Delay.Delay.later" -> Just compileErasedApp
Expand Down
1 change: 1 addition & 0 deletions src/Agda2Hs/Compile/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ isSpecialType :: QName -> Maybe (Elims -> C (Hs.Type ()))
isSpecialType = prettyShow >>> \case
"Haskell.Prim.Tuple._×_" -> Just tupleType
"Haskell.Prim.Tuple._×_×_" -> Just tupleType
"Haskell.Extra.Sigma.Σ" -> Just tupleType
"Haskell.Extra.Erase.Erase" -> Just unitType
"Haskell.Extra.Delay.Delay" -> Just delayType
_ -> Nothing
Expand Down
9 changes: 9 additions & 0 deletions test/Tuples.agda
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ test2 = case t1 of \where

{-# COMPILE AGDA2HS test2 #-}

open import Haskell.Extra.Sigma as S using (Σ-syntax)
open import Haskell.Extra.Dec
open import Haskell.Prim using (itsTrue)
open import Haskell.Extra.Refinement

t4 : Σ[ n ∈ Nat ] (Dec (IsTrue (n <= 5)))
t4 = 3 S., (True ⟨ itsTrue ⟩)

{-# COMPILE AGDA2HS t4 #-}
5 changes: 5 additions & 0 deletions test/golden/Tuples.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Tuples where

import Numeric.Natural (Natural)

swap :: (a, b) -> (b, a)
swap (a, b) = (b, a)

Expand All @@ -25,3 +27,6 @@ test2
= case t1 of
(a, b, c) -> c

t4 :: (Natural, Bool)
t4 = (3, True)

0 comments on commit 68eab23

Please sign in to comment.