Skip to content

Instantly share code, notes, and snippets.

@markandrus
Last active October 2, 2015 06:50
Show Gist options
  • Save markandrus/48fc7a1cb4933c2918c5 to your computer and use it in GitHub Desktop.
Save markandrus/48fc7a1cb4933c2918c5 to your computer and use it in GitHub Desktop.
Roundtrip a String through Vect and back
module Main
import Data.Vect
listToVect : List a -> (n ** Vect n a)
listToVect [] = (0 ** [])
listToVect (a :: as) with (listToVect as)
| (n ** as') = (1 + n ** a :: as')
stringToVect : String -> (n ** Vect n Char)
stringToVect = listToVect . unpack
vectToList : Vect n a -> List a
vectToList [] = []
vectToList (a :: as) = a :: vectToList as
vectToString : Vect n Char -> String
vectToString = pack . vectToList
roundtrip : String -> String
roundtrip s with (stringToVect s)
| (_ ** s') = vectToString s'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment