Skip to content

Instantly share code, notes, and snippets.

@maiermic
Last active April 4, 2016 20:20
Show Gist options
  • Select an option

  • Save maiermic/9440758a27312ba09988ffca90a48bee to your computer and use it in GitHub Desktop.

Select an option

Save maiermic/9440758a27312ba09988ffca90a48bee to your computer and use it in GitHub Desktop.
reverse Data.HVect in Idris
module reverse_hvect
import Data.HVect
reverse : HVect ts -> HVect (reverse ts)
reverse [] = []
reverse (x::xs) = (reverse xs) ++ [x]
@maiermic
Copy link
Author

maiermic commented Apr 4, 2016

I try to reverse a Data.HVect but my code results in an error:

Type checking .\reverse_hvect.idr
reverse_hvect.idr:7:9:When checking right hand side of reverse_hvect.reverse with expected type
        HVect (reverse (t :: ts))

Type mismatch between
        HVect (Data.Vect.reverse, go Type k ts [] ts ++ [t]) (Type of reverse xs ++ [x])
and
        HVect (Data.Vect.reverse, go Type (S k) (t :: ts) [t] ts) (Expected type)

Specifically:
        Type mismatch between
                Data.Vect.reverse, go Type k ts [] ts ++ [t]
        and
                Data.Vect.reverse, go Type (S k) (t :: ts) [t] ts
Holes: reverse_hvect.reverse

An example how reverse should work:

myHVect : HVect [Int, String, List Nat]
myHVect = [42, "text", [1, 2, 3]]

reversedHVect : HVect [List Nat, String, Int]
reversedHVect = reverse myHVect -- should be: [[1, 2, 3], "text", 42]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment