Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between type "a" and type "t" in Haskell type signature?

is there any difference between the two types "a" and "t" in Haskell type signature or its only a different designation like type "a" and type "b"?

in https://www.haskell.org/tutorial/goodies.html type [a] is defined as followed:

[a] is the family of types consisting of, for every type a, the type of lists of a. Lists of integers (e.g. [1,2,3]), lists of characters (['a','b','c']), even lists of lists of integers, etc., are all members of this family. (Note, however, that [2,'b'] is not a valid example, since there is no single type that contains both 2 and 'b'.)

is this definition also applied for type "t" ?

an example might be :

foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
  app :: [t] -> t -> [t]
like image 684
alixander Avatar asked Sep 14 '17 14:09

alixander


1 Answers

In Haskell type definitions, type names always start with upper-case letters, whereas type variables always start with lower-case letters. These are normally called a, b, and so on, but can also be called f, m, t, and so on.

Often, the letters in the beginning of the alphabet are used for unbounded type variables, whereas you often see more specific type variables denoted with f, m, t, and so on.

In the particular example

foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b

t is specifically denoted as being an instance of the Foldable type class. t a means any Foldable 'container' that holds values of the type a.

When you look your other example

app :: [t] -> t -> [t]

it might as well have said [a] -> a -> [a], if app is a 'free-standing' function. If, on the other hand, app belongs to a type class, that type class definition could contain a more specific definition of t.

like image 73
Mark Seemann Avatar answered Jan 01 '23 10:01

Mark Seemann