mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-11-24 15:07:37 +03:00
[ refactor ] more efficient implementation of range
This commit is contained in:
parent
f255026d1b
commit
09d8e25441
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user