Haskell - Illegal polymorphic type?

Why is single-use use of this type compiled, but its inclusion in the list fails?

ft1  :: (Foldable t, Num a) => t a -> a
ft1   =   (F.foldl (+)  0)

fTest :: [(Foldable t, Num a) => t a -> a ]
fTest = [ F.foldl (+)  0 ]

The latter gives an error:

folding.hs:80:10:
    Illegal polymorphic or qualified type:
      (Foldable t, Num a) => t a -> a
    Perhaps you intended to use ImpredicativeTypes
    In the type signature for `fTest':
      fTest :: [(Foldable t, Num a) => t a -> a]

Symmetrically, trying to call it unsuccessfully (in different ways):

type Ftst t a = (Foldable t, Num a) => t a -> a

folding.hs:80:1:
    Illegal polymorphic or qualified type:
      (Foldable t, Num a) => t a -> a
    Perhaps you intended to use RankNTypes or Rank2Types
    In the type declaration for `Ftst'
+4
source share
1 answer

Haskell , . -1 (. ) . -2 , , , 2- . 3 . ; GHC , ( ) , , . ( , GHC , , "" .)

: -1 "" , -1

forall a_1 ... a_m. (C_1, ..., C_n) => t

Rank-2 -1; n (n-1).

, . ( !), ; . , . , , , [] forall t a. (Foldable t, Num a) => t a -> a, , .

+12

Source: https://habr.com/ru/post/1570814/


All Articles