Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type GenTree<'data> =
- |Leaf of 'data
- |SubTree1 of GenTree<'data>* 'data * GenTree<'data>
- |Empty
- //higher order shit
- type Calc =
- |Operator of (float->float->float)
- |Operand of float
- // |Operator of 'op
- //|Operand of float
- //4.2 Funktionen op som tar en operator och två delträd som input och returnerar ett aritmetiskt träd
- let returnOp oper t1 t2 =
- calculator.SubTree1(t1, oper, t2)
- //4.3 Funktionen Eval tar ett aritmetisk träd som argument, räknar ut det och returnerar float värdet, ta hänsyn till division med 0
- let rec Eval tree =
- match tree with
- |calculator.Leaf (Operand x) -> x
- |calculator.SubTree1(tl, oper, tr) -> (oper (Eval tl) (Eval tr))
- |calculator.Empty -> 0.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement