3 people like it.
Like the snippet!
Microsoft: DEV207.1x Programming in F#
Snippet for assignment problem of module 3
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
|
// No idea if I got this right...but I use some of the data types we learned in module 3...
module mainModule
open System
type numberAndItsGoldenRatio =
{ number : int
goldenRatio : float }
let GetGoldenRatio number =
number * Math.Sqrt(5.0) / 2.0
let GetNumberAndItsGoldenRatio number =
{ number = number
goldenRatio = GetGoldenRatio(float number) }
[<EntryPoint>]
let main argv =
Console.WriteLine("Please enter some numbers. I will calculate the golden ratio for you")
let numbersAndTheirGoldenRatio =
[ let mutable run = true
while run do
Console.WriteLine("Do you want to add more numbers (y/n)? ")
if Console.ReadLine().ToLower() = "y" then
Console.WriteLine("Enter a number: ")
let number = Console.ReadLine()
yield GetNumberAndItsGoldenRatio (int number)
else run <- false ]
for x in numbersAndTheirGoldenRatio do
printfn "Number: %A, GR: %A" x.number x.goldenRatio
Console.ReadKey()
0
//////////////////////////////////////////////////////////////////////////
//update from: Musa Jahanghir also on http://pastebin.com/2EcsFVq7
open System
let ϕ = 0.5 + 0.5 * Math.Sqrt 5.0
[<EntryPoint>]
let main argv =
printf "Enter the length for the list (positive integer): " //SIZE
let lol = Console.ReadLine() |> int
let lof = [ for i in 1..lol -> printf "Enter a number %i: " i //READ
Console.ReadLine() |> float]
lof |> List.map (fun x -> printfn "%A" (x, x * ϕ)) |> ignore //WRITE
Console .ReadKey() |> ignore //WRAP
0
///////////////////////////////////////////////////////////////////////////
|
module mainModule
namespace System
type numberAndItsGoldenRatio =
{number: int;
goldenRatio: float;}
Full name: mainModule.numberAndItsGoldenRatio
numberAndItsGoldenRatio.number: int
Multiple items
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.int<_>
numberAndItsGoldenRatio.goldenRatio: float
Multiple items
val float : value:'T -> float (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.float
--------------------
type float = Double
Full name: Microsoft.FSharp.Core.float
--------------------
type float<'Measure> = float
Full name: Microsoft.FSharp.Core.float<_>
val GetGoldenRatio : number:float -> float
Full name: mainModule.GetGoldenRatio
val number : float
type Math =
static val PI : float
static val E : float
static member Abs : value:sbyte -> sbyte + 6 overloads
static member Acos : d:float -> float
static member Asin : d:float -> float
static member Atan : d:float -> float
static member Atan2 : y:float * x:float -> float
static member BigMul : a:int * b:int -> int64
static member Ceiling : d:decimal -> decimal + 1 overload
static member Cos : d:float -> float
...
Full name: System.Math
Math.Sqrt(d: float) : float
val GetNumberAndItsGoldenRatio : number:int -> numberAndItsGoldenRatio
Full name: mainModule.GetNumberAndItsGoldenRatio
val number : int
Multiple items
type EntryPointAttribute =
inherit Attribute
new : unit -> EntryPointAttribute
Full name: Microsoft.FSharp.Core.EntryPointAttribute
--------------------
new : unit -> EntryPointAttribute
val main : argv:string [] -> int
Full name: mainModule.main
val argv : string []
type Console =
static member BackgroundColor : ConsoleColor with get, set
static member Beep : unit -> unit + 1 overload
static member BufferHeight : int with get, set
static member BufferWidth : int with get, set
static member CapsLock : bool
static member Clear : unit -> unit
static member CursorLeft : int with get, set
static member CursorSize : int with get, set
static member CursorTop : int with get, set
static member CursorVisible : bool with get, set
...
Full name: System.Console
Console.WriteLine() : unit
(+0 other overloads)
Console.WriteLine(value: string) : unit
(+0 other overloads)
Console.WriteLine(value: obj) : unit
(+0 other overloads)
Console.WriteLine(value: uint64) : unit
(+0 other overloads)
Console.WriteLine(value: int64) : unit
(+0 other overloads)
Console.WriteLine(value: uint32) : unit
(+0 other overloads)
Console.WriteLine(value: int) : unit
(+0 other overloads)
Console.WriteLine(value: float32) : unit
(+0 other overloads)
Console.WriteLine(value: float) : unit
(+0 other overloads)
Console.WriteLine(value: decimal) : unit
(+0 other overloads)
val numbersAndTheirGoldenRatio : numberAndItsGoldenRatio list
val mutable run : bool
Console.ReadLine() : string
val number : string
val x : numberAndItsGoldenRatio
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Console.ReadKey() : ConsoleKeyInfo
Console.ReadKey(intercept: bool) : ConsoleKeyInfo
val printf : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printf
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val map : mapping:('T -> 'U) -> list:'T list -> 'U list
Full name: Microsoft.FSharp.Collections.List.map
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
More information