Agda: my code does not print a check (how to get implicit arguments correctly?)

"checkSimple" gets u, the universe element is U and checks (nat 1) can be converted to the agda type given by u. The result of the conversion is returned.

Now I am trying to write a console program and get "someU" from the command line.

So I changed the type of "checkSimple" to include the parameter (u: Maybe U) as the parameter (perhaps because the console input might be "nothing"). However, I can not get the code to check the type.

module CheckMain where


open import Prelude

-- Install Prelude
---- clone this git repo:
---- https://github.com/fkettelhoit/agda-prelude

-- Configure Prelude
--- press Meta/Alt and the letter X together
--- type "customize-group" (i.e. in the mini buffer)
--- type "agda2"
--- expand the Entry "Agda2 Include Dirs:"
--- add the directory 



data S : Set where
  nat  : (n : ℕ) → S
  nil  : S

sToℕ : S → Maybe ℕ
sToℕ (nat n) = just n
sToℕ _       = nothing


data U : Set where
  nat     : U

El : U → Set
El nat = ℕ


sToStat : (u : U) → S → Maybe (El u)
sToStat nat           s = sToℕ s


-- Basic Test
test1 : Maybe ℕ
test1 = sToStat nat (nat 1)


{- THIS WORKS -}

checkSimple : (u : U) → Maybe (El u)
checkSimple someU = sToStat someU (nat 1)



{- HERE IS THE ERROR -}

-- in contrast to checkSimple we only get a (Maybe U) as a parameter
-- (e.g. from console input)

check : {u : U} (u1 : Maybe U) → Maybe (El u)
check (just someU) = sToStat someU (nat 1)
check _ = nothing


{- HER IS THE ERROR MESSAGE -}

{- 
someU != .u of type U
when checking that the expression sToStat someU (nat 1) has type
Maybe (El .u)
-}
+5
source share
1 answer

: sToStat (u : U ); sToStat check, , someU - but check promises, u : U !


, typecheck, , .

, u1 nothing? , nothing. nothing ? Maybe (El u), , - u , , . , u!

Agda , check, , u , check, u, . , Agda :

check {u = nat} {- ... -}

.

, u :

data U : Set where
    nat char : U

. , :

El : U → Set
El nat  = ℕ
El char = Char

, check {u = char} (just nat)? sToStat someU (nat 1) Maybe ℕ, El u Char!


. - check u1. - unJust,

check : (u1 : Maybe U) → Maybe (El (unJust u1))

- , u1 - just. nothing, !

, - nothing. , u , - . Maybe ⊤ ( , , () Haskell - ).

check return Maybe ℕ Maybe ⊤ ? , !

Maybe-El : Maybe U → Set
Maybe-El nothing  = Maybe ⊤
Maybe-El (just u) = Maybe (El u)

, ! check :

check : (u : Maybe U) → Maybe-El u
check (just someU) = sToStat someU (nat 1)
check nothing      = nothing

, . Maybe-El , .

Maybe-El₂ : Maybe U → Set
Maybe-El₂ = Maybe ∘ helper
  where
    helper : Maybe U → Set
    helper nothing  = ⊤
    helper (just u) = El u

, , :

Maybe-El₂ : Maybe U → Set
Maybe-El₂ = Maybe ∘ maybe El ⊤

, Maybe-El Maybe-El₂ , . ∀ x → Maybe-El x ≡ Maybe-El₂ x. . Maybe-El x, , x? , . - x .

Maybe-El₂? : Maybe-El₂ x, () . , :

Maybe-El₂ x ⟶ (Maybe ∘ helper) x ⟶ Maybe (helper x)

, helper x , x. , , Maybe-El. ?

:

discard : {A : Set} → Maybe A → Maybe ⊤
discard _ = nothing

, , typecheck.

discard₂ : Maybe U → Maybe ⊤
discard₂ = discard ∘ check

check Maybe y y, ? , : , check x : Maybe-El x, x, , Maybe-El x Maybe y !

Maybe-El₂ . , Maybe-El₂ x Maybe y, discard₂ typechecks!

+8

All Articles