[ refactor ] more efficient implementation of range

This commit is contained in:
Guillaume ALLAIS 2021-03-29 23:01:56 +01:00 committed by G. Allais
parent f255026d1b
commit 09d8e25441

View File

@ -1,5 +1,6 @@
module Data.Vect module Data.Vect
import Data.DPair
import Data.List import Data.List
import Data.Nat import Data.Nat
import public Data.Fin import public Data.Fin
@ -755,10 +756,29 @@ diag : Vect len (Vect len elem) -> Vect len elem
diag [] = [] diag [] = []
diag ((x::xs)::xss) = x :: diag (map tail xss) diag ((x::xs)::xss) = x :: diag (map tail xss)
public export namespace Fin
range : {len : Nat} -> Vect len (Fin len)
range {len=Z} = [] public export
range {len=S _} = FZ :: map FS range tabulate : {len : Nat} -> (Fin len -> a) -> Vect len a
tabulate {len = Z} f = []
tabulate {len = S _} f = f FZ :: tabulate (f . FS)
public export
range : {len : Nat} -> Vect len (Fin len)
range = tabulate id
namespace Subset
public export
tabulate : {len : Nat} -> (Subset Nat (`LT` len) -> a) -> Vect len a
tabulate {len = Z} f = []
tabulate {len = S _} f
= f (Element Z ltZero)
:: Subset.tabulate (\ (Element n prf) => f (Element (S n) (LTESucc prf)))
public export
range : {len : Nat} -> Vect len (Subset Nat (`LT` len))
range = tabulate id
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Zippable -- Zippable