When starting out with Haskell, I found it difficult to read a lot of the symbols. I made this document explaining the names of some symbols and how I read them.
x :: Int
x has type Int
Int -> String
Int to String
The type Int -> String
takes an Int as an argument and evaluates to a String.
We say this type is "Int to String".
foo :: a -> b -> c
foo has type a to b to c
This symbol is for declaring type class constraints. A type class lets us define common methods across types. It limits a type.
foo :: (Bar a) => a -> b
for all a of type class Bar, foo has type a to b
List cons operator. Adds the first argument to the front of the second. In
module Data.List
. I believe the name comes from Lisp, for "constructing"
or "construction"
(:) :: a -> [a] -> [a]
1 : [2, 3] == [1, 2, 3]
List index operator
(!!) :: [a] -> Int -> a
[1, 2, 3] !! 1 == 2
Element in the list [1, 2, 3] at index 1
Used in list comprehensions (and called a generator there) and monadic do notation
x <- something
x drawn from something
Also used for function guards.
[ x * x | x <- [1, 2, 3], x > 1 ]
A list of x multiplied by x such that x is drawn from the list [1, 2, 3], where x is greater than 1.
Monadic bind operator. Part of type class Monad.
(>>=) :: Monad m => m a -> (a -> m b) -> m b
Monadic sequence operator. Part of type class Monad.
(>>) :: Monad m => m a -> m b -> m b
x >> y
x then y
An infix synonym for fmap
I believe, for this function
!!
you could read it as "element at" or something along the lines ...