Tidy up
This commit is contained in:
103 files changed
+3663
-3779
No files matched your search
@@ -22,8 +22,6 @@ intORbin :: Parser Int
|
||||
expr :: Parser AST
|
||||
```
|
||||
|
||||
|
||||
|
||||
```
|
||||
λ> parse (symbol "something") "nothing"
|
||||
[]
|
||||
@@ -59,8 +57,6 @@ instance Functor Parser where
|
||||
in [(g x, src1)] )
|
||||
```
|
||||
|
||||
|
||||
|
||||
```
|
||||
λ> parse (fmap (+3) integer) "42 blah blah"
|
||||
[(45, blah blah)]
|
||||
@@ -75,7 +71,7 @@ instance Functor Parser where
|
||||
*** Exception Non-exhaustive patterns
|
||||
```
|
||||
|
||||
fixing `fmap`
|
||||
Fixing `fmap`
|
||||
|
||||
```haskell
|
||||
fmap g pa = P (\src -> [ (g x, src1) | (x,src1) <- parse pa src])
|
||||
@@ -152,11 +148,9 @@ pf <*> pa = P (\src -> [ (f x, src2) | (f,src1) <- parse pf src,
|
||||
[(10201, ""), (25, "")]
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Monad Class of Parser
|
||||
|
||||
Monad class will facilitate the use of `do` notation.
|
||||
The Monad class will facilitate the use of `do` notation.
|
||||
|
||||
```haskell
|
||||
instance Monad Parser where
|
||||
@@ -228,7 +222,7 @@ pa >>= fpb = P (\src -> [ r | (x,src1) <- parse pa src,
|
||||
-- second part will look at 113, realise it is not a binary digit and just read 11 which is equal to 3 hence true
|
||||
```
|
||||
|
||||
What is the do notation and how is it connected to the bind function, we will show this by writing a simple parser
|
||||
What is the `do` notation and how is it connected to the bind function? We will show this by writing a simple parser
|
||||
|
||||
```haskell
|
||||
pairSum :: Parser Int
|
||||
@@ -262,8 +256,6 @@ parse (symbol "number" >> integer) "number 9"
|
||||
NOTE: >> is a non-dependant bind
|
||||
```
|
||||
|
||||
|
||||
|
||||
```haskell
|
||||
the grammer
|
||||
--funApp ::= ( simpleFun integer )
|
||||
@@ -402,7 +394,7 @@ string (c:cs) = do char c
|
||||
[(' ',"hello")]
|
||||
```
|
||||
|
||||
We have to fix leading white space causing failure
|
||||
We have to fix leading whitespace causing failure
|
||||
|
||||
```haskell
|
||||
space :: Parser ()
|
||||
@@ -463,4 +455,3 @@ expr = do t1 <- mexpr
|
||||
<|>
|
||||
return t1)
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user