[英]Agda stdlib List max
我正在嘗試獲取Data.List
的最大元素:
listMax : max ℕ (2 ∷ 1 ∷ []) ≟ 2
listMax = ?
但不明白為什么我會收到這個錯誤:
Set !=< (Relation.Binary.Bundles.TotalOrder _b_20 _ℓ₁_21 _ℓ₂_22)
when checking that the expression ℕ has type
Relation.Binary.Bundles.TotalOrder _b_20 _ℓ₁_21 _ℓ₂_22
我猜 ℕ 應該是Relation.Binary.Bundles.TotalOrder _b_20 _ℓ₁_21 _ℓ₂_22
類型的東西,但我不知道如何獲得那種類型的東西,為什么需要它來獲得最大元素。
編輯
查看Data.List.Extrema
max
的簽名,我看到:
max : B → List B → B
我看到這里定義了 B
open TotalOrder totalOrder renaming (Carrier to B)
我不知道為什么ℕ不能成為載體。
我還在Data.Fin.Properties
找到:
≤-totalOrder : ℕ → TotalOrder _ _ _
並嘗試
listMax : {n : ℕ} → max (≤-totalOrder n) (2 l.∷ 1 l.∷ l.[]) ≡ 2
但我現在收到此錯誤:
List _A_27 !=< Fin n
when checking that the inferred type of an application
List _A_27
matches the expected type
Relation.Binary.Bundles.TotalOrder.Carrier (≤-totalOrder n)
謝謝!
在Data.String.Base
找到此示例后:
rectangle : ∀ {n} → Vec (ℕ → String → String) n →
Vec String n → Vec String n
rectangle pads cells = Vec.zipWith (λ p c → p width c) pads cells where
sizes = List.map length (Vec.toList cells)
width = max 0 sizes
我發現對max
的調用應該看起來像
max 0 (2 l.∷ l.[])
還發現我錯過了導入:
open import Data.List.Extrema ℕₚ.≤-totalOrder
出於我還不知道的原因,使用此導入不會出現錯誤:
ℕ != (Relation.Binary.TotalOrder _b_26 _ℓ₁_27 _ℓ₂_28)
when checking that the expression 0 has type
Relation.Binary.TotalOrder _b_26 _ℓ₁_27 _ℓ₂_28
我從做這個導入中得到的:
open import Data.List.Extrema (max)
我仍然很好奇導入的原因
open import Data.List.Extrema ℕₚ.≤-totalOrder
工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.