Haskell notes

Lackings

  • IDE, non-working on vscode. Formatting, go to def, go to source, rename
  • Package management, version conflicts. Easily fork & new npm pkg
  • Build time slow, fragile, corruption
  • Cross platform (macos win linux), works on my machine
  • New dev, easily pickup setup, easily search & doc

Solved

  • How to avoid Exception: empty list in real life
  • Precedence in filter c `elem` ['a'..'z'] ++ ['A'..'Z'] ++ [0..9] s, and use of $
  • ERR map (\xs) (subsets t) ERR map (\xs) (subsets t) FIX map (\xs -> xs) (subsets t) A value vs a function that returns a value
  • Predicate and range at same time? [ x*y x <- [2,5,10], y <- [8,10,11], x*y > 50]
  • Horrible stack build behavior - must go to global project to build to make global stack.yaml effective
  • Deal with Maybe/Just
  • Random IO monad: state Couldn’t match expected type ‘[a]’ with actual type ‘IO [Int]’
  • do block
  • error :: [Char] -> a invoke runtime/system API
  • 签名结合顺序和应用顺序相反!
  • Flip
    flip' :: (a -> b -> c) -> (b -> a -> c)
    flip' f = let g x y = f y x in g
    -- flip' f = g
    --   where g x y = f y x
    

TODO

  • Nothing vs (), Nothing is just for Maybe? Nothing is a value constructor for Maybe type
  • Type language is fragile
      data AB = A {
        a :: Int
      } | B {
        b :: Int
      } deriving (Show)
      select :: AB -> Int
      select (A a) = a
      select (B b) = b
    
  • Why use let in do block? But you can’t outside
  • expect Text actual String https://stackoverflow.com/questions/37894987/couldnt-match-expected-type-text-with-actual-type-char
  • dot vs dollar
      putStrLn . reverseWords $ line
      putStrLn . reverseWords line -- err!
    
  • Precedence? -> Biggest revelation: function is an instance of Functor typeclass!
    unwords . words <$> reverse
    unwords . reverse <$> words
    
  • Use sequence for [IO Foobar] to IO [Foobar]
Written on November 1, 2018