No type class instance was found

Hello everybody,

I’m experimenting with typesafe routing and compiling of this code:

module Routing where

import Type.Proxy (Proxy(Proxy))

import Data.Symbol (class IsSymbol, SProxy(SProxy), reflectSymbol)

import Record (insert, get)

data Param (label :: Symbol) ty = Param

class ParseParam a where
  parseParam :: String -> Maybe a
  renderParam :: a -> String

class CreatePath xs params where
  createPath :: Proxy xs -> Record params -> String

instance paramCreatePath :: ( IsSymbol label, ParseParam ty ) => CreatePath (Param label ty) params where
  createPath _ params = renderParam (get (SProxy :: SProxy label) params)

results in this error:

No type class instance was found for
    Routing.ParseParam t0
  The instance head contains unknown type variables. Consider adding a type annotation.

while applying a function renderParam
  of type ParseParam t0 => t0 -> String
  to argument (get SProxy) params
while checking that expression renderParam ((get SProxy) params)
  has type String
in value declaration paramCreatePath

where t0 is an unknown type

See for more information,
or to contribute content related to this error.

I understand error as ty is of unknown type, but I would like to awoid specify it to by able to work with everithing in typeclass ParseParam

Thank you in advance

The problem is that you haven’t said anything about the contents of the params record; presumably you want to assert that the record field identified by the label symbol has type ty? If so, I think you can do that with a Cons constraint, like Cons label ty unused params.

1 Like

Thank you, that was it