Using a polymorphic type in a type family in haskell

I am studying the type of family, but it is so confusing. When I define a polymorphic type outside the class definition, it works well.

{-# LANGUAGE Rank2Types #-} type T = Num a => a 

But when a polymorphic type is defined inside a class definition,

 {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE Rank2Types #-} data D = D class A a where type T a :: * instance AD where type TD = Num a => a 

then complier shows an error:

 Illegal polymorphic or qualified type: forall a. Num a => a In the type instance declaration for 'T' In the instance declaration for 'AD' 

Is there a way to make a function in a class whose return type is polymorphic, for example 3 (Num a => a)?

+7
haskell
source share

No one has answered this question yet.

See related questions:

757
Getting started with Haskell
534
Large-scale design in Haskell?
39
A "type family" with a "data family" in short?
eleven
Illegal polymorphic or qualified type using RankNTypes and TypeFamilies
7
Normalize instance family type in Haskell template
5
Polymorphic function within type family
3
Haskell - polymorphism and values โ€‹โ€‹depending on types
3
Type Family Equivalent `Eq`?
2
Writing cool lenses for family type posts?
2
Haskell: instance definitions for type families

All Articles