How to compare types for equality?

I tried to compare a Stringand Stringwhile waiting True.

Idris> String == String
Can't find implementation for Eq Type

Then I expected Falsewhen comparing Stringwith a Bool.

Idris> String /= Bool
Can't find implementation for Eq Type

Am I missing import?

+5
source share
2 answers

You cannot, because he broke the parametricity that we have in Idris. We cannot match type matching. But it is necessary to write an implementation Eq, for example:

{- Doesn't work!
eqNat : Type -> Bool
eqNat Nat = True
eqNat _ = False -}

In addition, if you can match the image by type, they will be needed at runtime. Types are currently erased during compilation.

+6
source

: , , . , , Refl, (=) xx, . ( )

:

twoPlusTwoEqFour : 2 + 2 = 4
twoPlusTwoEqFour = Refl

:

stringEqString : String = String
stringEqString = Refl

stringEqInt : String = Int
stringEqInt = Refl

-- type error: Type mismatch between String and Int

, , , n + 0 :

proof : n = n + 0
0

Source: https://habr.com/ru/post/1683571/


All Articles