Haskell Type Signature with Compound / Multiparameter Type Constructors

I found these types of type signatures:

x :: a b -> Int
x f = 3

y :: a b c -> Int
y f = 3

z :: a b c d -> Int
z f = 3

> x [1] -- 3
> y (1, 2) -- 3
> z (1, 2, 3) -- 3

Basically:

  • x accepts only a value related to a constructor of type with 1 parameter or more.
  • y accepts only a value related to a type constructor with two or more parameters.
  • z takes only a value related to a type constructor with three or more parameters.

They are valid, but I'm not sure what they mean and that they can be used.

They are apparently associated with polytypic concepts or polymorphism over type constructors, but they use an invariant based on many parameters that the type constructor accepts.

+4
source share
2

. , , . a -> Int: a, !

, , , , toInteger :: Integral a => a -> Integer, . ,

import Data.Foldable
import Prelude hiding (foldr)

x' :: (Foldable a, Integral b) => a b -> Integer
x' = foldr ((+) . toInteger) 0

, a b ... n o p q, a b ... p , , Functor, Applicative Monad; Foldable, Traversable Comonad; a b ... o Arrow... , , .

+8

@leftaroundabout GHCI . , . a b c ~ (((a) b) c), a (b c) - (a ((b) c). , a b c , a * -> * -> * a b * -> * a b c *.

GHCI gist (https://gist.github.com/CMCDragonkai/2a1d3ecb67dcdabfc7e0) ( )

0

All Articles