types

Cards (16)

  • basic data types:
    Bool: True False
    Integer: ... -1 0 1 ...
    Int: -9223372036854775808 ... 9223372036854775807
    Float, Doubles: 0.123 -4.5e6
    Char: 'a' ... 'A' ... '1' ...
    String: "Hello World" "yolo"
  • create new types:
    data TwoStrings = TwoStr String String
  • data TwoStrings = TwoStr String String
    TwoStrings is the new type
    TwoStr is a constructor
  • type of function: length
    Foldable t => t a -> Int
  • type of function: product
    (Foldable t, Num a) => t a -> a
  • type of function: sum
    [Int] -> Int
  • type of function: head
    [a] -> a
  • type of function: tail
    [a] -> [a]
  • func :: ?
    func 0 = []
    func n = n : func (n-1)
    Int -> [Int]
  • func :: ?
    func = [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5 ,'e')]
    [(Int, Char)]
  • func :: ?
    func x [] = [x]
    func x (y:ys) = y : func x ys
    Int -> [Int] -> [Int]
  • :t map
    (a -> b) -> [a] -> [b]
  • :t filter
    (a -> Bool) -> [a] -> [a]
  • :t zip
    [a] -> [b] -> [(a, b)]
  • :t unzip
    [(a, b)] -> ([a], [b])
  • :t zipWith
    (a -> b -> c) -> [a] -> [b] -> [c]