1 people like it.

Complex 1 - Intro

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
// Define the Complex type as a record
type Complex = 
    { Re : float
      Im : float };;

// Make some complex numbers
let z1 = {Re = 1.0; Im = 4.0};;
let z2 = {Re = 2.0; Im = -2.0};;

// printing strings are OK
printfn "Hello";;
// Error - don't know how to print a Complex
//printfn z1;; // <-- Error 

// print anything with '%A'
printfn "%A" z1;;

// Make our own printing for Complex (using float formatting %f, 3 decimals)
let print z = printfn "%.3f%+.3fi" z.Re z.Im;;
 
// ... and try it out
print z1;;
Complex.Re: float
Multiple items
val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = System.Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
Complex.Im: float
val z1 : Complex

Full name: Script.z1
val z2 : Complex

Full name: Script.z2
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val print : z:Complex -> unit

Full name: Script.print
val z : Complex
Raw view Test code New version

More information

Link:http://fssnip.net/6J
Posted:14 years ago
Author:
Tags: