Skip to content

Commit 4e6de7e

Browse files
committed
Add special rules for Nat zero and suc constructors
1 parent 4bfd155 commit 4e6de7e

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/Agda2Hs/Compile/Name.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ toNameImport x (Just mod) =
6565
defaultSpecialRules :: SpecialRules
6666
defaultSpecialRules = Map.fromList
6767
[ "Agda.Builtin.Nat.Nat" `to` "Natural" `importing` Just "Numeric.Natural"
68+
, "Agda.Builtin.Nat.Nat.zero" `to` "0" `importing` Nothing
69+
, "Agda.Builtin.Nat.Nat.suc" `to` "succ" `importing` Nothing
6870
, "Haskell.Prelude.coerce" `to` "unsafeCoerce" `importing` Just "Unsafe.Coerce"
6971
, "Agda.Builtin.Int.Int" `to` "Integer" `importing` Nothing
7072
, "Agda.Builtin.Word.Word64" `to` "Word" `importing` Nothing

test/Succeed/ZeroSuc.agda

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module ZeroSuc where
2+
3+
open import Haskell.Prelude
4+
5+
test1 : Nat
6+
test1 = zero
7+
8+
{-# COMPILE AGDA2HS test1 #-}
9+
10+
test2 : Nat Nat
11+
test2 = suc
12+
13+
{-# COMPILE AGDA2HS test2 #-}
14+
15+
data MyNat : Set where
16+
MyZero : MyNat
17+
MySuc : MyNat MyNat
18+
19+
{-# COMPILE AGDA2HS MyNat #-}
20+
21+
opaque
22+
test3 : MyNat Nat
23+
test3 MyZero = zero
24+
test3 (MySuc n) = suc (test3 n)
25+
26+
{-# COMPILE AGDA2HS test3 #-}

test/Succeed/ZeroSuc.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module ZeroSuc where
2+
3+
import Numeric.Natural (Natural)
4+
5+
test1 :: Natural
6+
test1 = 0
7+
8+
test2 :: Natural -> Natural
9+
test2 = succ
10+
11+
data MyNat = MyZero
12+
| MySuc MyNat
13+
14+
test3 :: MyNat -> Natural
15+
test3 MyZero = 0
16+
test3 (MySuc n) = succ (test3 n)
17+

0 commit comments

Comments
 (0)