| Safe Haskell | Safe-Inferred |
|---|
Lessons.Lesson08
Description
Notes taken by Julija Mikeliūnaitė
Synopsis
- fl :: [Int]
- fm :: Maybe Integer
- fe :: Either String Integer
- fe' :: Either Integer Integer
- fio :: IO String
- p :: [Integer]
- am :: Maybe Integer
- am' :: Maybe Integer
- am'' :: Maybe Integer
- al :: [Integer]
- ml :: [Integer]
- newtype Parser a = Parser {
- runParser :: String -> Either String (a, String)
- parseLetter :: Parser Char
- threeLetters :: Parser String
- parseString :: Parser String
- parseNonEmptyString :: Parser String
Documentation
Monad is the most powerful class. Bind method (>>=) gives the illusion of sequential computation.
Functors ignore the order of execution.
| Minimal implementation of a functor: fmap :: Functor f => (a -> b) -> f a -> f b It takes a pure function (which takes a and returns b), a functor of a, and returns a functor of b.
The function was applied to every element of the list.
>>>fl[5,4]
Takes an input and returns the value with "!"" in the end. Returned type is IO String. IO is a type which presents computations which originate in the external world.
Applicative functor is between functor and monad.
pure is pretty much the same as return: pure :: Applicative f => a -> f a return :: Monad m => a -> m a
>>>p[5]
Sources of values are completely independent, computed in parallel.
>>>al[2,3,3,4,4,5]
Sources of values depend on values that are above, line-by-line.
>>>ml[2,3,3,4,4,5]
newtype is used if ADT has a single constructor.
Instances
| Alternative Parser Source # | Signature |, sometimes called |
| Applicative Parser Source # | |
| Functor Parser Source # | |
| Monad Parser | If a list of names is provided, it returns a list of numbers (type IO [Integer]).
Return type is [IO Integer] (not IO [Integer]).
Usually functions with _'s drop the final result and only run side-effects. Running a bunch of computations when you don't really care about the result.
Closest thing Haskell has to loop (similar to
The number next to M shows how many arguments the first function takes. Works as ($).
Lifts a pure function into a monadic function.
Same result as before.
Using our helpers in the context of parsers (making them useful).
After the first parser completes its course, the second parser continues with the unparsed string.
Pretty much every program is just a traversable. Allows to write parser combinators in a monadic way. |
parseLetter :: Parser Char Source #
If a number is parsed, then it returns Left value.
>>>runParser parseLetter "skfhsdk"Right ('s',"kfhsdk")
threeLetters :: Parser String Source #
parseString :: Parser String Source #
parseNonEmptyString :: Parser String Source #