Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pp:2023:haskell:l10 [2023/05/13 15:37]
alexia.ciuclea
pp:2023:haskell:l10 [2023/05/15 19:15] (current)
tpruteanu
Line 48: Line 48:
 <code haskell> <code haskell>
 mminus :: Maybe Nat -> Maybe Nat -> Maybe Nat mminus :: Maybe Nat -> Maybe Nat -> Maybe Nat
-mminus m n = ???+mminus m n = undefined
  
 mplus :: Maybe Nat -> Maybe Nat -> Maybe Nat mplus :: Maybe Nat -> Maybe Nat -> Maybe Nat
-mplus m n = ???+mplus m n = undefined
 </​code>​ </​code>​
  
Line 57: Line 57:
 <code haskell> <code haskell>
 mmulti :: Maybe Nat -> Maybe Nat -> Maybe Nat mmulti :: Maybe Nat -> Maybe Nat -> Maybe Nat
-mmulti m n = ???+mmulti m n = undefined
 </​code>​ </​code>​
  
-===== 10.3. Implementing our '​Parser'​ =====+===== 10.2. Implementing our '​Parser'​ =====
 Firstly we need to understand the role of our parser. Firstly we need to understand the role of our parser.
 Given the type: Given the type:
Line 99: Line 99:
  
 charParser :: Char -> Parser Char charParser :: Char -> Parser Char
-charParser c = ???+charParser c = undefined
 </​code>​ </​code>​
  
Line 105: Line 105:
 <code haskell> <code haskell>
 predicateParser :: (Char -> Bool) -> Parser Char predicateParser :: (Char -> Bool) -> Parser Char
-predicateParser p = ???+predicateParser p = undefined
 </​code>​ </​code>​
  
 Now that we know how to build basic parser, we should start sequencing them. We can rely  on Monads for this purpose. Add the following lines to your code, they should be familiar from the lecture: Now that we know how to build basic parser, we should start sequencing them. We can rely  on Monads for this purpose. Add the following lines to your code, they should be familiar from the lecture:
 +<​hidden>​
 <code haskell> <code haskell>
 instance Monad Parser where instance Monad Parser where
Line 138: Line 139:
                                 x -> x                                 x -> x
 </​code>​ </​code>​
 +</​hidden>​\\
 +\\
 Here we have built our Parser Monad, made it an Applicative,​ Functor and Alternative. Alternative type-class allows us to switch between parsers in case one fails. This will be needed later in the exercises. Applicative type-class is necessary, but shall be excluded from our discussion. Here we have built our Parser Monad, made it an Applicative,​ Functor and Alternative. Alternative type-class allows us to switch between parsers in case one fails. This will be needed later in the exercises. Applicative type-class is necessary, but shall be excluded from our discussion.
  
Line 143: Line 146:
 <code haskell> <code haskell>
 varP :: Parser String varP :: Parser String
-varP = ???+varP = undefined
 </​code>​ </​code>​
  
Line 157: Line 160:
  
 plusParser :: (Parser a) -> Parser [a] plusParser :: (Parser a) -> Parser [a]
-plusParser p = ???+plusParser p = undefined
  
 starParser :: (Parser a) -> Parser [a] starParser :: (Parser a) -> Parser [a]
-starParser p = ???+starParser p = undefined
 </​code>​ </​code>​
  
Line 168: Line 171:
 <code haskell> <code haskell>
 varParser :: Parser String ​ varParser :: Parser String ​
-varParser = ???+varParser = undefined
  
 varExprParser :: Parser Expr      varExprParser :: Parser Expr     
-varExprParser = ???+varExprParser = undefined
 </​code>​ </​code>​
  
Line 177: Line 180:
 <code haskell> <code haskell>
 whitespaceParser :: Parser String whitespaceParser :: Parser String
-whitespaceParser = ???+whitespaceParser = undefined
 </​code>​ </​code>​
  
Line 183: Line 186:
 <code haskell> <code haskell>
 exprParser :: Parser Expr exprParser :: Parser Expr
-exprParser = ???+exprParser = undefined
 </​code>​ </​code>​