Created
March 11, 2018 01:19
-
-
Save zhaar/4bd95170f9835b3cd630059919039b04 to your computer and use it in GitHub Desktop.
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.List | |
%default total | |
data PathComp : Type where | |
Empty : String -> PathComp | |
Printable : (t : Type) -> (t -> String) -> PathComp | |
Str' : PathComp | |
Str' = Printable String id | |
data Showable : Type -> Type where | |
ToShow : Show a => Showable a | |
implicit | |
emptyPath : String -> PathComp | |
emptyPath = Empty | |
--implicit <- this implicit wont resolve | |
typeToPath : (t : Type) -> {auto prf : Showable t} -> PathComp | |
typeToPath t {prf = ToShow} = Printable t show | |
syntax "~" [e] = typeToPath e | |
URLPath : Type | |
URLPath = List PathComp | |
URLPathToSig : URLPath -> Type | |
URLPathToSig [] = String | |
URLPathToSig ((Empty x) :: xs) = URLPathToSig xs | |
URLPathToSig ((Printable t f) :: xs) = t -> URLPathToSig xs | |
pathToFuncAcc : (p : URLPath) -> String -> URLPathToSig p | |
pathToFuncAcc [] x = x | |
pathToFuncAcc ((Empty y) :: xs) str = pathToFuncAcc xs (str ++ "/" ++ y) | |
pathToFuncAcc ((Printable t f) :: xs) str = \arg => pathToFuncAcc xs (str ++ "/" ++ (f arg)) | |
pathToFunc : (p : URLPath) -> URLPathToSig p | |
pathToFunc p = pathToFuncAcc p "" | |
unitTest: String | |
unitTest = pathToFunc ["username", Str', "id", ~Int] "abc" 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment