Last active
December 19, 2020 22:05
-
-
Save ebresafegaga/4ffcb2840978f9846a421c6a36a83121 to your computer and use it in GitHub Desktop.
It's all about the motive, baby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Vect | |
-- This is a paramorphism (aka primitive recursion) on Vectors | |
foldr : (motive : (k : Nat) -> Vect k a -> Type) -> | |
((l : Nat) -> (x : a) -> (xs : Vect l a) -> motive l xs -> motive (S l) (x :: xs)) -> | |
motive Z [] -> | |
(vec : Vect n a) -> | |
motive n vec | |
foldr {n = Z} motive step base [] = base | |
foldr {n = S k} motive step base (x :: xs) = step k x xs (foldr motive step base xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment