1 people like it.
Like the snippet!
qModule.fsx
Testing
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:
|
open System
module qModule =
type Shape = // define a "union" of alternative structures
| Circle of int
| Rectangle of int * int
| Polygon of (int * int) list
| Point of (int * int)
let draw shape = // define a function "draw" with a shape param
match shape with
| Circle radius ->
printfn "The circle has a radius of %d" radius
| Rectangle (height,width) ->
printfn "The rectangle is %d high by %d wide" height width
| Polygon points ->
printfn "The polygon is made of these points %A" points
| _ -> printfn "I don't recognize this shape"
let circle = Circle(10)
let rect = Rectangle(4,5)
let polygon = Polygon( [(1,1); (2,2); (3,3)])
let point = Point(2,3)
[circle; rect; polygon; point] |> List.iter draw
|
namespace System
module qModule
from Script
type Shape =
| Circle of int
| Rectangle of int * int
| Polygon of (int * int) list
| Point of (int * int)
Full name: Script.qModule.Shape
union case Shape.Circle: int -> Shape
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<_>
union case Shape.Rectangle: int * int -> Shape
union case Shape.Polygon: (int * int) list -> Shape
type 'T list = List<'T>
Full name: Microsoft.FSharp.Collections.list<_>
union case Shape.Point: (int * int) -> Shape
val draw : shape:Shape -> unit
Full name: Script.qModule.draw
val shape : Shape
val radius : int
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val height : int
val width : int
val points : (int * int) list
val circle : Shape
Full name: Script.qModule.circle
val rect : Shape
Full name: Script.qModule.rect
val polygon : Shape
Full name: Script.qModule.polygon
val point : Shape
Full name: Script.qModule.point
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 iter : action:('T -> unit) -> list:'T list -> unit
Full name: Microsoft.FSharp.Collections.List.iter
More information