I'm just starting to learn haskell. I have custom class
class MyClass a where
doSomething :: a -> ()
Can I write a data with polymorphic callback in constructor?
data MyData = MyConstructor {
callback :: (MyClass m) => m -> () -- error
}
I want to make constraint for function argument.
In short, Yes you can by using Rank2Types or RankNTypes pragma.
As your data type is existentially quantified. It is actually
data MyData = MyConstructor (forall m. MyClass m => m -> ())
for which you require higher rank extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With