Last active
August 9, 2020 14:26
-
-
Save Woody88/0093bf4c1946c2de1ccc93327823eb07 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
Could not match type | |
() | |
with type | |
( id :: Int | |
) | |
while trying to match type () | |
with type ( id :: Int | |
) | |
while solving type class constraint | |
Prim.Row.Cons "capture" | |
(Record t0) | |
t1 | |
t1 | |
while inferring the type of parseRoute urlSpec | |
in value declaration it | |
where t0 is an unknown type | |
t1 is an unknown type |
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
class ReadCapture a where | |
readCapture :: String -> Maybe a | |
class ParseRoute (url :: Symbol) (specs :: # Type) (conn :: # Type) where | |
parseRoute :: SProxy url -> RProxy specs -> String -> Either String { | conn } | |
class ParsePath (xs :: PList) (specs :: # Type) (from :: # Type) (to :: # Type) | xs -> from to where | |
parsePath :: PProxy xs -> RProxy specs -> String -> String -> Either String (Builder { | from } { | to }) | |
instance parsePathNil :: ParsePath PNil specs to to where | |
parsePath _ _ _ _ = pure identity | |
instance parseCapture :: | |
( IsSymbol var | |
, IsSymbol capture | |
, Symbol.Cons h t capture | |
, Symbol.Cons h t "capture" | |
, Row.Cons var vtype ctail ctype | |
, Row.Cons var vtype from' to | |
, ReadCapture vtype | |
, Row.Lacks var ctail | |
, Row.Cons capture { | ctype } from' to | |
, Row.Cons capture { | ctail } from' from' | |
, ParsePath tail spcstl from from' | |
) => ParsePath (PCons (CaptureVar var) tail) (RL.Cons capture { | ctype} spcstl) from to where | |
parsePath _ specs url url' = do | |
let { after, before } = String.splitAt 1 url | |
(Tuple var tail) = case flip String.splitAt after <$> readIndex after of | |
Nothing -> (Tuple after "") | |
Just {after: after', before: before'} -> Tuple before' after' | |
case readCapture var of | |
Nothing -> Left "capture could not be parsed." | |
Just (v :: vtype) -> do | |
rest <- parsePath (PProxy :: _ tail) (RLProxy :: _ spcstl) tail url' | |
let x = Builder.modify captureP (\r -> Record.insert varP v r) | |
pure $ x <<< rest | |
where | |
readIndex u = String.indexOf (Pattern "/") u <|> String.indexOf (Pattern "?") u | |
captureP = (SProxy :: _ capture) | |
varP = (SProxy :: _ var) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment