Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.47 KB | None | 0 0
  1. //1+2 |> ignore
  2. //let a = 4 * 6
  3. //let raisePowerTwo x = x ** 2.0
  4. //let y = raisePowerTwo 3.0
  5. //let s = @"apple\n"
  6. //let c : System.Char = 'X'
  7. //let b = true
  8. //printfn "%.3f" 5.0
  9. //printfn "%A" "apple"
  10. //let add a b = a + b
  11. //let addFour = add 4
  12. //
  13. //addFour 7
  14. //
  15. //let add4 b = 4 + b
  16. //
  17. //let add2 (a, b) = a + b
  18. //
  19. //add2 (4,7)
  20. //
  21. //let halfway a b=
  22. //    let dif = b - a
  23. //    let mid = dif / 2
  24. //    mid + a
  25. //
  26. //halfway 5 11
  27. //halfway 11 5
  28. //let halfway5 = halfway 5
  29. //halfway5 11
  30. //let defineMessage () =
  31. //    let message = "Hello"
  32. //    printfn "%s" message
  33. //    let message = "Hi"
  34. //    printfn "%s" message
  35. //
  36. //defineMessage ()
  37. //
  38. let mathsPuzzle () =
  39.     printf "Enter the day of the month on which you were born: "
  40.     let input = int ( System.Console.ReadLine() )
  41.     let x = input * 4
  42.     let x = x + 13
  43.     let x = x * 25
  44.     let x = x - 200
  45.     printf " Enter number of the month you were born: "
  46.     let input = int ( System.Console.ReadLine() )
  47.     let x = x + input
  48.     let x = x * 2
  49.     let x = x - 40
  50.     let x = x * 50
  51.     printf " Enter the last two digits of the year of your birth:"
  52.     let input = int ( System.Console.ReadLine() )
  53.     let x = x + input
  54.     let x = x - 10500
  55.     printf "Date of birth (ddmmyy): %i" x
  56.  
  57. mathsPuzzle ()
  58.  
  59. let changeType () =
  60.     let x = 1
  61.     let x = "change me"
  62.     let x = x + 1
  63.     printf "%s" x
  64.  
  65. let rec fact x =
  66.     if x = 0 then
  67.         1
  68.     else
  69.         x * fact ( x - 1 )
  70.  
  71. fact 5
  72.  
  73. let rec fib n =
  74.     match n with
  75.     | 0 -> 0
  76.     | 1 -> 1
  77.     | x -> fib ( x - 1 ) + fib ( x - 2 )
  78.  
  79. fib 10
  80.  
  81. let add a b = a + b
  82.  
  83. let add2 = fun a b -> a + b
  84.  
  85. let add3 = fun a -> (fun b -> a + b)
  86.  
  87. let add4 = function a -> function b -> a + b
  88.  
  89. let f = function
  90.         | x when x < 10 -> "less than 10"
  91.         |_              -> "not less than 10"
  92.  
  93.  
  94. let f2 = fun x ->
  95.     match x with
  96.     | x when x < 10 -> "less than 10"
  97.     |_              -> "not less than 10"
  98.  
  99. let s = "one, " ^ "two, " ^ "three"
  100. let date = System.DateTime.Now + new System.TimeSpan( 365, 0, 0, 0 )
  101.  
  102. let (+) a b = a - b
  103.  
  104. 4 + 5
  105.  
  106. "apple" + "pie"
  107.  
  108. let (+*) a b = (a+b)*a*b
  109.  
  110. let x = 34 +* 3
  111.  
  112. let list1 = []
  113. let list2 = 1 :: []
  114. let list3 = 1 :: 2 :: []
  115. let list4 = [1;2;3;4]
  116. let list5 = [1; 2 ] @ [ 3; 4; 5; 6 ]
  117.  
  118. let rec print_elements list =
  119.     match list with
  120.     | [] -> ()
  121.     | head :: tail ->
  122.         printfn "%A" head
  123.         print_elements tail
  124.        
  125. print_elements [1; 2; 3; 4]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement