-
Notifications
You must be signed in to change notification settings - Fork 5
/
live1.fsx
84 lines (60 loc) · 1.69 KB
/
live1.fsx
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(*
ITT8060 -- Advanced Programming 2013
Department of Computer Science
Tallinn University of Technology
------------------------------------
Lecture 1: Lightning Introduction
James Chapman and Juhan Ernits
Material based on chapter 2 of Expert F#
*)
let text = "All the king's horses and all the king's men"
text <- ""
let splitAtSpaces (text : string) : list<string> = text.Split ' ' |> Array.toList
splitAtSpaces text
let wordCount text =
let words = splitAtSpaces text
let wordSet = Set.ofList words // number of unique words
let numWords = words.Length
let numDups = numWords - wordSet.Count
numWords , numDups
wordCount text
let showWordCount text =
let numWords, numDups = wordCount text
printfn "--> %d words in text" numWords
printfn "--> %d duplicate words" numDups
showWordCount text
let badDefinition1 =
let words = splitAtSpaces input
let input = "We three kings"
words.Length
let badDefinition2 = badDefinition2 + 1
let powerOfFourPlusTwo n =
let n = n * n
let n = n * n
let n = n + 2
n
let site1 = "http://www.cnn.com", 10
let site2 = "http://news.bbc.co.uk", 5
let site3 = "http://www.msnbc.co.uk", 4
let sites = site1, site2, site3
fst site2
snd site2
let url, rel = site2
let fst (a, b) = a
let snd (a, b) = b
let a , b = 1 , 2 , 3
// side effects
let two = printfn "Hello world"; 1 + 1
let four = two + two
open System.IO
open System.Net
let http (url: string) =
let req = WebRequest.Create url
let resp = req.GetResponse()
let stream = resp.GetResponseStream()
let reader = new StreamReader(stream)
let html = reader.ReadToEnd()
resp.Close()
html
let x = http "http://news.err.ee"
let rec fact n = if n <= 1 then 1 else fact n