Haskell unsafeInterleaveIO and Lazy list constructed from IO actions

Haskell is a lazy language, which means you can easily define an infinite list with recursion ... -> IO ByteString hGetContentsNLazy k h = lazyRead where lazyRead = unsafeInterleaveIO $ do ... cs) :} To make it lazy, simply add the unsafeInterleaveIO in front of the recursion body. Here ... and the chunk list is constructed on demand.

Maybe monad: where is the join and nested Nothing

is the definition of Maybe monad: instance Monad Maybe where return = Just Nothing >>= _ = Nothing ... arrow. The definiton of Maybe functor and fmap: instance Functor Maybe where -- fmap :: (a -> b ... ) -> Maybe a -> Maybe b fmap _ Nothing = Nothing fmap f (Just x) = Just (f x) You can blend the f ... , fmap and join together, the result is the same as bind, the process will be like this Nothing

Haskell map mapM mapM_ example

The Control.Monad module contains a series of functions like mapM, mapM_, how and when to use ... unsafePerformIO $ foo !! 1 Now change the map to mapM. Evaluate it in repl will trigger the IO action one ... by one the type of the mapM version is IO [()]. You can read it as IO of list of actions, the map ... of mapM_ is mapM_ f list = sequence_ (map f list).

Haskell typeclasses and automatic derivation

To make a type an instance of a class, we can either provide our implementation or use the default implementation by a mechanism called deriving.

The default implementaion will be exactly what you expected.

Understanding the parenthesis in Haskell

Parenthesis is one of the most important syntax element in Haskell, unlike LISP, in which parenthesis is used for everything and always represent a list, Haskell use it in various different ways. This may add a little overhead for learning process. This is where the good old LISP shine, you don't have to learn about syntax since there is .

Haskell pattern matching and pattern overlap

In Haskell the patterns is written down one after another, it acts as a kind of case selection, when matching, those patterns are matched one by one, in the order that they are written down

In this case the order doesn't matter, they are distinct patterns, we can write it in different order with no problem