Created
April 5, 2016 10:57
-
-
Save maiermic/c7b4d62843f82af3ab3a0a3fbdd2ee49 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| module reverse_vect | |
| import Data.Vect | |
| myReverse : Vect n a -> Vect n a | |
| myReverse [] = [] | |
| myReverse (x::xs) = (myReverse xs) ++ [x] |
Author
Hi, it should be:
module reverse_vect
import Data.Vect
myReverse : Vect n a -> Vect n a
myReverse [] = []
myReverse {n = S k} (x::xs) = rewrite plusCommutative 1 k in (myReverse xs) ++ [x]The reason that k + 1 is not S k is that + is defined to recurse on the left argument in Nat. So k + 1 would not reduce any further since k is unknown rewriting with plusCommutative ensures that the arguments are flipped so that k + 1 becomes 1 + k which can reduce to S k. The reason that the type of myReverse xs ++ [x] is k + 1 is because of the definition of ++ which adds the length of the given arguments in the resulting Vect 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I try to reverse a
Data.Vectbut my code results in an error:How can I fix it?