Вопрос

I want to write the function which accepts values of types, which has instances of multiparameter type class together with every type. Something like this (signature of test function is illegal):

class Test a b

test :: forall a. (forall b. Test a b) => a -> a

Is there a way to express such restriction?

Это было полезно?

Решение

Depending on what you're trying to achieve, there may be a better solution.

But what you're asking is also possible, using the constraints package.

{-# LANGUAGE FlexibleContexts, ConstraintKinds, MultiParamTypeClasses #-}

import Data.Constraint.Forall

class Test a b

test :: Forall (Test a) => a -> a
test = undefined
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top