The next big Haskell project is about to start! If I break, you can: 1. Restart: M-x haskell-process-restart 2. Configure logging: C-h v haskell-process-log (useful for debugging) 3. General config: M-x customize-mode 4. Hide these tips: C-h v haskell-process-show-debug-tips λ> :k Maybe Maybe :: * -> * λ> :k Eq Eq :: * -> Constraint λ> :k Countable Countable :: (* -> *) -> Constraint λ> :k [] [] :: * -> * λ> :k ([] Int) ([] Int) :: * λ> :k [Int] [Int] :: * λ> :t length length :: Foldable t => t a -> Int λ> count [1..10] 10 λ> count Data.t 3 λ> count tree 5 λ> elements Data.t [3,1,5] λ> elements Data.t [1,3,5] λ> elements Data.tree [1,2,3,4,5] λ> fmap (+2) [1..10] [3,4,5,6,7,8,9,10,11,12] λ> fmap (+2) t Node {root = 5, left = Node {root = 3, left = Empty, right = Empty}, right = Node {root = 7, left = Empty, right = Empty}} λ> fmap (+2) tree Tree {val = 3, subtrees = SubTree {firstTree = Tree {val = 4, subtrees = None}, restTrees = SubTree {firstTree = Tree {val = 5, subtrees = SubTree {firstTree = Tree {val = 6, subtrees = None}, restTrees = None}}, restTrees = SubTree {firstTree = Tree {val = 7, subtrees = None}, restTrees = None}}}} λ> (+2) <$> [1..10] [3,4,5,6,7,8,9,10,11,12] λ> (+2) <$> Data.t Node {root = 5, left = Node {root = 3, left = Empty, right = Empty}, right = Node {root = 7, left = Empty, right = Empty}} λ> (+2) <$> Data.tree Tree {val = 3, subtrees = SubTree {firstTree = Tree {val = 4, subtrees = None}, restTrees = SubTree {firstTree = Tree {val = 5, subtrees = SubTree {firstTree = Tree {val = 6, subtrees = None}, restTrees = None}}, restTrees = SubTree {firstTree = Tree {val = 7, subtrees = None}, restTrees = None}}}} λ> (+2) $ 5 7 λ> (+2) <$> (Just 5) Just 7 λ> (+2) <$> Nothing Nothing λ> :k Either Either :: * -> * -> * λ> (+2) <$> (Left 5) Left 5 λ> (+2) <$> (Right 5) Right 7 λ> :t (,) (,) :: a -> b -> (a, b) λ> :k (,) (,) :: * -> * -> * λ> (+2) <$> (5, 7) (5,9) λ> :k (->) (->) :: TYPE q -> TYPE r -> * λ> :k ((->) Int String) ((->) Int String) :: * λ> :k (Int -> String) (Int -> String) :: * λ> (+2) <$> (*3) (+2) <$> (*3) :: Num b => b -> b λ> (+2) <$> (*3) $ 5 17 λ> (+2) <$> getInt 5 7 λ> getLine asdsa "asdsa" λ> ("Hello " ++) <$> getLine Trifon "Hello Trifon" λ> :t (*>) (*>) :: Applicative f => f a -> f b -> f b λ> (+2) <$> Just 100 Nothing λ> (+) <$> Just 2 <*> Just 3 Just 5 λ> (+) <$> Nothing <*> Just 3 Nothing λ> (+) <$> Just 2 <*> Nothing Nothing λ> (+) <$> Right 2 <*> Right 3 Right 5 λ> (+) <$> Right 2 <*> Left "abc" Left "abc" λ> (+) <$> Left "error" <*> Right 3 Left "error" λ> (+) <$> Right 2 <*> Left "erro" Left "erro" λ> (+) <$> [1,3,5] <*> [2,4,6] [3,5,7,5,7,9,7,9,11] λ> (^3) <$> ((+) <$> [1,3,5] <*> [2,4,6]) [27,125,343,125,343,729,343,729,1331] λ> ZipList [1..5] ZipList [1..5] :: (Enum a, Num a) => ZipList a λ> getZipList (ZipList [1..5]) [1,2,3,4,5] λ> (+) <$> ZipList [1,3,5] <*> ZipList [2,4,6] (+) <$> ZipList [1,3,5] <*> ZipList [2,4,6] :: Num b => ZipList b λ> (+) <$> ZipList [1,3,5] <*> ZipList [2,4,6] ZipList {getZipList = [3,7,11]} λ> const 2 3 2 λ> (+) <$> (*3) <*> (*5) $ 2 16 λ> (+) <$> getInt <*> getInt 5 8 13 λ> liftA2 (+) getInt getInt 5 8 13 λ> sequenceA [Just 2, Just 3, Just 5] Just [2,3,5] λ> sequenceA [Just 2, Nothing, Just 5] Nothing λ> sequenceA [(+2), (*3), (+5)] sequenceA [(+2), (*3), (+5)] :: Num a => a -> [a] λ> sequenceA [(+2), (*3), (+5)] 1 [3,3,6] λ> sequenceA [(+2), (*3), (+5)] 1 [3,3,6] λ> :i IO newtype IO a = GHC.Types.IO (GHC.Prim.State# GHC.Prim.RealWorld -> (# GHC.Prim.State# GHC.Prim.RealWorld, a #)) -- Defined in ‘GHC.Types’ instance Applicative IO -- Defined in ‘GHC.Base’ instance Functor IO -- Defined in ‘GHC.Base’ instance Monad IO -- Defined in ‘GHC.Base’ instance MonadPlus IO -- Defined in ‘GHC.Base’ instance Monoid a => Monoid (IO a) -- Defined in ‘GHC.Base’ λ> Just 3 >>= getAt' [1..5] Just 4 λ> Just 10 >>= getAt' [1..5] Nothing λ> [1..5] >>= (\x -> [-1..x]) [-1,0,1,-1,0,1,2,-1,0,1,2,3,-1,0,1,2,3,4,-1,0,1,2,3,4,5] λ> do x <- [1..5]; return [-1..x] [[-1,0,1],[-1,0,1,2],[-1,0,1,2,3],[-1,0,1,2,3,4],[-1,0,1,2,3,4,5]] λ> do x <- [1..5]; [-1..x] [-1,0,1,-1,0,1,2,-1,0,1,2,3,-1,0,1,2,3,4,-1,0,1,2,3,4,5] λ> do x <- [1..5]; y <- [-1..x]; return y [-1,0,1,-1,0,1,2,-1,0,1,2,3,-1,0,1,2,3,4,-1,0,1,2,3,4,5] λ> [ y | x <- [1..5], y <- [-1..x] ] [-1,0,1,-1,0,1,2,-1,0,1,2,3,-1,0,1,2,3,4,-1,0,1,2,3,4,5] λ> (+2) >>= (\x -> (*x)) $ 3 15 λ> (+2) >>= (\x -> (*x)) $ 10 120 λ>