Hello,
I have typeclass
class (RequestReader m) <= MatchRequest m xs (fromParams :: # Type) (toParams :: # Type) (fromMatched :: # Type) (toMatched :: # Type) where
matchRequest :: Proxy xs -> (Matching fromParams fromMatched) -> m (Maybe (Matching toParams toMatched))
and I have instance
instance methodMatchRequest :: ( IsSymbol method, RequestReader m, Lacks "method" fromMatched, Cons "method" Matched fromMatched toMatched) => MatchRequest m (Method method) unused unused fromMatched toMatched where
matchRequest method matching = getMethod >>= \requestMethod ->
pure $ if requestMethod == (reflectSymbol (SProxy :: SProxy "method"))
then Just (mark (SProxy :: SProxy "method") matching)
else Nothing
which results into error
Error found:
in module Routing
at src/Routing.purs:118:18 - 118:50 (line 118, column 18 - line 118, column 50)
Could not match type
( method :: Matched
| fromMatched0
)
with type
toMatched1
while trying to match type ( method :: Matched
| fromMatched0
)
with type toMatched1
while solving type class constraint
Prim.Row.Cons "method"
Matched
fromMatched0
toMatched1
while inferring the type of mark SProxy
in value declaration methodMatchRequest
where fromMatched0 is a rigid type variable
bound at (line 0, column 0 - line 0, column 0)
toMatched1 is a rigid type variable
bound at (line 0, column 0 - line 0, column 0)
Background is that I’m experimenting with typelevel routing and I’m triing to define router that can match also headers and method…, but I’m triing to also have sanity check that would fail compile time if route definition is triing to match method tvice, or triing to match same header twice. I’m triing to achieve it using Cons and Lack from Type.Row
by adding matched parts of request as fields to record and then checking using Lacks
if they vere not defined on record, record that should contain matched parts named matched
in definitions,
any idea how implement that class this way?
or is there any deeper mistake?