What does this syntax mean in Haskell: ([]: _)

I saw this with the function ([]: _)

Unable to find its definition (Google does not work with characters). So what is it?

type Mat a = [[a]]

myTranspose :: Mat a -> Mat a
myTranspose ([]:_) = []
myTranspose p = (map head p) : myTranspose (map tail p)
+4
source share
1 answer

This matches the pattern for the list of lists. It corresponds to a list with at least one element, where the first element is an empty list . For example [[]], or [[], [2,4]], [[], [], [1,4], [2], [5]].

A list in Haskell is defined as a linked list with two constructors: []an empty list and (a:as)"cons", where a- "head" (the first element of the list), and astail (a list containing the rest of the elements).

, _ " ". , cons (a:as), a ( ) - [], as - _, .

myTranspose , , .

+13

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


All Articles