1

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?

leventov
  • 14,760
  • 11
  • 69
  • 98
  • 3
    no, there is not. But perhaps you can workaround it; can you give us a small example of what you are trying to achieve? Perhaps you can do with just a single-parameter type class that has methods that universally quantify over what is now the second parameter of your class? – Stefan Holdermans Jan 09 '13 at 14:52

1 Answers1

3

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
Roman Cheplyaka
  • 37,738
  • 7
  • 72
  • 121