Add the rest of university notes

This commit is contained in:
John Gatward committed 2026-10-04 14:02:35 +01:00
1 parent c1b84c7f7d
commit d0f27f276b
366 files changed
+9844 -110

No files matched your search

@@ -0,0 +1,41 @@
# Functional Parsers
In our parser - there's a lot of repeated code and a lot of cases.
Types of scanner and parser are very similar
```haskell
scanToken :: String -> Maybe (Token, String)
parseTerm :: [Token] -> Maybe (AST, [Token])
parseExp :: [Token] -> Maybe (AST, [Token])
general :: [c] -> Maybe (a, [c])
lessGeneral :: String -> Maybe (a, String)
--remember :t string :: [char]
-- [c] list of characters or tokens
Parser a :: String -> [(a, String)]
-- no maybe needed as failure is now returning an empty list
--The parser of type a, we can now define generic functions that operate on a given type => less repeated code
--This is an instance of a typeclass (monad yikes)
```
Do notation
```haskell
Parser a = String -> [(a, String)]
symbol :: String -> Parser ()
-- no need to define result, as all it does it succeed or fail
exp :: Parser AST
parseParenthesis :: Parser AST
parseParenthesis = do symbol '('
t <- exp
symbol ')'
return t
```