Skip to content

Commit a0256a9

Browse files
ZambonifofexMatthewDaggitt
authored andcommitted
add Maybe type for Haskell interop (#700)
1 parent d160aa4 commit a0256a9

File tree

5 files changed

+98
-8
lines changed

5 files changed

+98
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ New modules
155155
Data.Vec.Bounded.Base
156156
Data.Vec.Bounded
157157
158+
Foreign.Haskell.Pair
159+
Foreign.Haskell.Maybe
160+
158161
Relation.Binary.Construct.Closure.Reflexive.Properties
159162
Relation.Binary.Construct.Closure.Reflexive.Properties.WithK
160163
Relation.Binary.Construct.Closure.Equivalence.Properties

GenerateEverything.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ unsafeModules = map toAgdaFilePath
3838
, "Data.Word.Unsafe"
3939
, "Debug.Trace"
4040
, "Foreign.Haskell"
41+
, "Foreign.Haskell.Maybe"
42+
, "Foreign.Haskell.Pair"
4143
, "IO"
4244
, "IO.Primitive"
4345
, "Reflection"

src/Foreign/Haskell.agda

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ module Foreign.Haskell where
1010

1111
open import Level
1212

13-
-- A pair type
13+
------------------------------------------------------------------------
14+
-- Pairs
1415

15-
record Pair {ℓ ℓ′ : Level} (A : Set ℓ) (B : Set ℓ′) : Set (ℓ ⊔ ℓ′) where
16-
constructor _,_
17-
field fst : A
18-
snd : B
19-
open Pair public
16+
open import Foreign.Haskell.Pair public
17+
renaming
18+
( toForeign to toForeignPair
19+
; fromForeign to fromForeignPair
20+
)
2021

21-
{-# FOREIGN GHC type AgdaPair l1 l2 a b = (a , b) #-}
22-
{-# COMPILE GHC Pair = data MAlonzo.Code.Foreign.Haskell.AgdaPair ((,)) #-}
22+
------------------------------------------------------------------------
23+
-- Maybe
2324

25+
open import Foreign.Haskell.Maybe public
26+
renaming
27+
( toForeign to toForeignMaybe
28+
; fromForeign to fromForeignMaybe
29+
)
2430

2531
------------------------------------------------------------------------
2632
-- DEPRECATED NAMES

src/Foreign/Haskell/Maybe.agda

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Which Maybe type which calls out to Haskell via the FFI
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K #-}
8+
9+
module Foreign.Haskell.Maybe where
10+
11+
open import Level
12+
import Data.Maybe as Data
13+
14+
private
15+
variable
16+
a : Level
17+
A : Set a
18+
19+
------------------------------------------------------------------------
20+
-- Definition
21+
22+
abstract
23+
24+
Maybe : Set a Set a
25+
Maybe = Data.Maybe
26+
27+
{-# FOREIGN GHC type AgdaMaybe l a = Maybe a #-}
28+
{-# COMPILE GHC Maybe = data AgdaMaybe (Just | Nothing) #-}
29+
30+
------------------------------------------------------------------------
31+
-- Conversion
32+
33+
abstract
34+
35+
toForeign : Data.Maybe A Maybe A
36+
toForeign x = x
37+
38+
fromForeign : Maybe A Data.Maybe A
39+
fromForeign x = x

src/Foreign/Haskell/Pair.agda

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- The Pair type which calls out to Haskell via the FFI
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K #-}
8+
9+
module Foreign.Haskell.Pair where
10+
11+
open import Level
12+
open import Data.Product using (_×_; _,_)
13+
14+
private
15+
variable
16+
a b : Level
17+
A : Set a
18+
B : Set b
19+
20+
------------------------------------------------------------------------
21+
-- Definition
22+
23+
abstract
24+
25+
Pair : Set a Set b Set (a ⊔ b)
26+
Pair = _×_
27+
28+
{-# FOREIGN GHC type AgdaPair l1 l2 a b = (a , b) #-}
29+
{-# COMPILE GHC Pair = data MAlonzo.Code.Foreign.Haskell.AgdaPair ((,)) #-}
30+
31+
------------------------------------------------------------------------
32+
-- Conversion
33+
34+
abstract
35+
36+
toForeign : A × B Pair A B
37+
toForeign x = x
38+
39+
fromForeign : Pair A B A × B
40+
fromForeign x = x

0 commit comments

Comments
 (0)