-- Issue #5
open import Agda.Builtin.Nat using (Nat)

data Bar : Set where
  bar : Bar

data Foo : Set where
  foo : {Bar}  Foo

fooToNat : Foo  Nat
fooToNat (foo {bar}) = 42

testFoo : Foo
testFoo = foo {bar}

-- Polymorphic variant.
data BarA {} (A : Set ) : Set  where
  bar : A  BarA A

data FooA {} (A : Set ) : Set  where
  foo : {BarA A}  FooA A

fooAToNat : FooA Nat  Nat
fooAToNat (foo {bar n}) = n

testFooA : FooA Nat
testFooA = foo {_}{_}{bar 42}

-- Record variant.

record BarR : Set where
  constructor bar
open BarR

record FooR : Set where
  constructor foo
  field {getBar} : BarR
open FooR

fooRToNat : FooR  Nat
fooRToNat (foo {bar}) = 42

testFooR : FooR
testFooR = foo {bar}

-- Polymorphic record variant.

record BarRA {} (A : Set ) : Set  where
  constructor bar
open BarRA

record FooRA {} (A : Set ) : Set  where
  constructor foo
  field {getBar} : BarRA A
open FooRA

fooRAToNat : FooRA Nat  Nat
fooRAToNat (foo {bar}) = 42

testFooRA : FooRA Nat
testFooRA = foo {_}{_}{bar}

{-# FOREIGN AGDA2RUST
pub fn main() {
  println!("{}:\t {} | {} | {} | {}", module_path!(),
    fooToNat(testFoo()),
    fooAToNat(testFooA()),
    fooRToNat(testFooR()),
    fooRAToNat(testFooRA()),
  );
}
#-}