Difference between type parameters and indices?

后端 未结 2 571
醉梦人生
醉梦人生 2020-11-28 08:50

I am new to dependent types and am confused about the difference between the two. It seems people usually say a type is parameterized by another type and indexe

2条回答
  •  误落风尘
    2020-11-28 09:08

    Here is an example of a type paramerised by some value:

    open import Data.Nat
    
    infixr 4 _∷_
    
    data ≤List (n : ℕ) : Set where
      []  : ≤List n
      _∷_ : {m : ℕ} -> m ≤ n -> ≤List n -> ≤List n
    
    1≤3 : 1 ≤ 3
    1≤3 = s≤s z≤n
    
    3≤3 : 3 ≤ 3
    3≤3 = s≤s (s≤s (s≤s z≤n))
    
    example : ≤List 3
    example = 3≤3 ∷ 1≤3 ∷ []
    

    It's a type of lists with every element less or equal n. The general intuition is: if some property holds for every inhabitant of a type, then you can abstract it into parameter. There is a mechanical rule also: "The first index can be turned into a new parameter if each constructor has the same variable on the first index position (in the result type)." This quote is from *, you should read it.

    • http://people.inf.elte.hu/divip/AgdaTutorial/Sets.Parameters_vs_Indices.html

提交回复
热议问题