| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- The Either type which calls out to Haskell via the FFI |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible #-} |
| 8 |
|
| 9 |
module Foreign.Haskell.Either where |
| 10 |
|
| 11 |
open import Level using (Level; _⊔_) |
| 12 |
open import Data.Sum.Base using (_⊎_; inj₁; inj₂) |
| 13 |
|
| 14 |
private |
| 15 |
variable |
| 16 |
a b : Level |
| 17 |
A : Set a |
| 18 |
B : Set b |
| 19 |
|
| 20 |
------------------------------------------------------------------------ |
| 21 |
-- Definition |
| 22 |
|
| 23 |
data Either (A : Set a) (B : Set b) : Set (a ⊔ b) where |
| 24 |
left : A → Either A B |
| 25 |
right : B → Either A B |
| 26 |
|
| 27 |
{-# FOREIGN GHC type AgdaEither l1 l2 a b = Either a b #-} |
| 28 |
{-# COMPILE GHC Either = data MAlonzo.Code.Foreign.Haskell.Either.AgdaEither (Left | Right) #-} |
| 29 |
|
| 30 |
------------------------------------------------------------------------ |
| 31 |
-- Conversion |
| 32 |
|
| 33 |
toForeign : A ⊎ B → Either A B |
| 34 |
toForeign (inj₁ a) = left a |
| 35 |
toForeign (inj₂ b) = right b |
| 36 |
{-# WARNING_ON_USAGE toForeign |
| 37 |
"Warning: toForeign was deprecated in 2.0. |
| 38 |
Please use Foreign.Haskell.Coerce.coerce instead." |
| 39 |
#-} |
| 40 |
|
| 41 |
fromForeign : Either A B → A ⊎ B |
| 42 |
fromForeign (left a) = inj₁ a |
| 43 |
fromForeign (right b) = inj₂ b |
| 44 |
{-# WARNING_ON_USAGE fromForeign |
| 45 |
"Warning: fromForeign was deprecated in 2.0. |
| 46 |
Please use Foreign.Haskell.Coerce.coerce instead." |
| 47 |
#-} |