Is it reasonable to have multi parameter type classes in PureScript?
The compiler raises an unreasonable 'No type class instance was found' error (see full output) for the below type class definition:
class Transform model turn where
transform :: turn -> model -> model
delay :: Maybe turn -> Int
The error arises from the definition of the delay
function which doesn't depend on the model
type parameter. As evident from the compiler output linked above it substitutes a t0 for the absent model.
What is the proper way to fix this? Currently I workaround this issue by changing the kind of turn
as below:
class Turnable model turn where
runTurn :: turn model -> model -> model
turnDelay :: Maybe (turn model) -> Int
rightfold from the FP slack channel gave this answer:
Consequently I changed the type class definition to this:
This made the compiler happy. For details, consult Functional dependencies (fundep) in the Haskell wiki and the 24 days of PureScript post.