Advertisement
Guest User

Untitled

a guest
Feb 15th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.96 KB | None | 0 0
  1. type GenTree<'data> =
  2.      |Leaf of 'data
  3.       |SubTree of  GenTree<'data> * 'data * GenTree<'data>
  4.  
  5.    type Calc =
  6.        |Operator of (float->float->float)
  7.        |Operand of float
  8.  
  9.    //Builds a tree of a list of ints
  10.  
  11.    let IsOperator (str:string) =
  12.        match str with
  13.        | "+" | "-" | "x" | "/" -> true
  14.        |_ -> false
  15.  
  16.    let parseToFloat (str:string list) =
  17.        System.Single.Parse <|  System.String.Concat((List.toSeq str))
  18.  
  19.    let SwapValue (str:string) =
  20.        match str with
  21.        |"+" -> (+)
  22.        |"-" -> (-)
  23.        |"x" -> (*)
  24.        |"/" -> (/)
  25.        |_ -> failwith "Not valid operator"
  26.  
  27.    let rec ConvertValueTree (list:string list) =
  28.        match list with
  29.        |x::x2::x3::xs when (not (IsOperator x2)) && (not (IsOperator x)) -> x::x2::(ConvertValueTree xs)
  30.        |x::x2::x3::xs when (IsOperator x2) && (not (IsOperator x) && ->
  31.        |_ -> failwith "Please insert more information"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement