Last active
October 2, 2015 06:50
-
-
Save markandrus/48fc7a1cb4933c2918c5 to your computer and use it in GitHub Desktop.
Roundtrip a String through Vect and back
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
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