Search code examples
haskelltypeclassforallmultiparameter

Predicate with forall quantifier in haskell?


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?


Solution

  • 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