Advertisement
Guest User

Untitled

a guest
Feb 15th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.85 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.    let IsOperator (str:string) =
  10.        match str with
  11.        | "+" | "-" | "x" | "/" -> true
  12.        |_ -> false
  13.  
  14.    let parseToFloat (str:string list) =
  15.        System.Single.Parse <|  System.String.Concat((List.toSeq str))
  16.  
  17.    let SwapValue (str:string) =
  18.        match str with
  19.        |"+" -> (+)
  20.        |"-" -> (-)
  21.        |"x" -> (*)
  22.        |"/" -> (/)
  23.        |_ -> failwith "Not valid operator"
  24.  
  25.    let rec ConvertValueTree (list:string list) =
  26.        match list with
  27.        |x::x2::x3::xs when (not (IsOperator x2)) && (not (IsOperator x)) -> x::x2::(ConvertValueTree xs)
  28.        |_ -> failwith "Please insert more information"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement