Difference between revisions of "FP Laboratory 9"

From Marek Běhálek Wiki
Jump to navigation Jump to search
(Created page with "== User defined data types and type classes == Consider following representation of expressions <syntaxhighlight lang="Haskell"> data Expr = Num Int | Add Expr Exp...")
 
Line 5: Line 5:
 
data Expr = Num Int
 
data Expr = Num Int
 
           | Add Expr Expr
 
           | Add Expr Expr
  | Sub Expr Expr
+
          | Sub Expr Expr
  | Mul Expr Expr
+
          | Mul Expr Expr
  | Div Expr Expr
+
          | Div Expr Expr
  | Var Char
+
          | Var Char
 
  deriving (Eq)
 
  deriving (Eq)
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 12:10, 18 September 2019

User defined data types and type classes

Consider following representation of expressions

data Expr = Num Int
          | Add Expr Expr
          | Sub Expr Expr
          | Mul Expr Expr
          | Div Expr Expr
          | Var Char
	  deriving (Eq)
  • Create function eval that evaluates expresions.
  • Create function showExpr that shows expression as a String.
  • Extend class Show to be usable with our expressions.
  • Create function derivation representing symbolic derivation of a given expression.