Skip to content

Instantly share code, notes, and snippets.

@hwclass
Created January 23, 2017 23:51
Show Gist options
  • Save hwclass/b8fa57aac28547372a64f1e0d6231398 to your computer and use it in GitHub Desktop.
Save hwclass/b8fa57aac28547372a64f1e0d6231398 to your computer and use it in GitHub Desktop.
F Sharp Notes
xyz = "xyz";;
 Stopped due to error
 System.Exception: Operation could not be completed due to earlier error
 The value or constructor 'xyz' is not defined at 2,0
let xyz = "xyz";;
 val xyz : string = "xyz"
"abc";;
 val it : string = "abc"
xvy;;
 Stopped due to error
 System.Exception: Operation could not be completed due to earlier error
 The value or constructor 'xvy' is not defined at 3,0
xyz;;
 val it : string = "xyz"
speed * time;;
xvy;;
 Stopped due to error
 System.Exception: Operation could not be completed due to earlier error
 The value or constructor 'xvy' is not defined at 3,0
let speed = 20;;
 val speed : int = 20
let time = 2;;
 val time : int = 2
speed * time;;
 val it : int = 40
val distance = 186;;
 Unexpected keyword 'val' in interaction at 3,0
 parse error at 3,0
let distance = 186;;
 val distance : int = 186
let time = 8;;
 val time : int = 8
speed = distance / time;;
 val it : bool = false
speed
;;
 val it : int = 20
let speed = distance / time;;
 val speed : int = 23
speed
;;
 val it : int = 23
let distance = 186.0;;
 val distance : float = 186.0
let speed = distance / time;;
 Stopped due to error
 System.Exception: Operation could not be completed due to earlier error
 The type 'int' does not match the type 'float' at 3,23
 The type 'int' does not match the type 'float' at 3,21
let time = 8.0;;
 val time : float = 8.0
let speed = distance / time;;
 val speed : float = 23.25
speed;;
 val it : float = 23.25
let squareFunction (input:int) =
let sq = input * input
sq
;;
val squareFunction : input:int -> int
squareFunction 5
;;
 val it : int = 25
// speed calculation
let speed (dist:float) = dist / 2.0;;
 val speed : dist:float -> float
speed 20.0;;
 val it : float = 10.0
let squareFunction (input:int) =
let sq = input * input
sq
;;
 val squareFunction : input:int -> int
squareFunction 5
;;
 val it : int = 25
(/*speed calculation*/)
;;
 Unexpected identifier in interaction. Expected ')' or other token. at 3,3
 Unmatched '(' at 3,0
 Unexpected symbol ')' in expression at 3,22
 parse error at 3,22
let speed (dist:float) = dist / 2.0;;
 val speed : dist:float -> float
speed 20.0;;
 val it : float = 10.0
 F# Interactive for F# 4.0 (private)
 Freely distributed under the Apache 2.0 Open Source License
 For help type #help;;
1 + 1 ;;
 val it : int = 2
let completed = 'completed';;
 Stopped due to error
 System.Exception: Operation could not be completed due to earlier error
 Unexpected quote symbol in binding at 3,16
let completed = "completed";;
 val completed : string = "completed"
completed;;
 val it : string = "completed"
let uncompleted = "uncompleted"
;;
 val uncompleted : string = "uncompleted"
let hello = "Hello";;
 val hello : string = "Hello"
let name = "Baris";;
 val name : string = "Baris"
hello + name;;
 val it : string = "HelloBaris"
"hello " + "Baris";;
 val it : string = "hello Baris"
"hello, " + "Baris";;
 val it : string = "hello, Baris"
let hello = "hello, ";;
 val hello : string = "hello, "
hello + 'Baris';;
 Unexpected quote symbol in expression at 3,8
 parse error at 3,8
hello + "Baris";;
 val it : string = "hello, Baris"
let name = "Baris";;
 val name : string = "Baris"
hello + name;;
 val it : string = "hello, Baris"
let greeting = hello + name;;
 val greeting : string = "hello, Baris"
greeting;;
 val it : string = "hello, Baris"
let location = 77.51,166.40,21
;;
 val location : float * float * int = (77.51, 166.4, 21)
let location = (77.51,166.40,21)
;;
 val location : float * float * int = (77.51, 166.4, 21)
let longAlt location =
let long,_,alt = location
(alt, long)
printfn "%A" (longAlt location);;
 (21, 77.51)
 val longAlt : 'a * 'b * 'c -> 'c * 'a
 val it : unit = ()
printfn "%A" (fst(longAlt location));;
 21
 val it : unit = ()
printfn "%A" (lst(longAlt location));;
 Stopped due to error
 System.Exception: Operation could not be completed due to earlier error
 The value or constructor 'lst' is not defined at 3,14
printfn "%A" (snd(longAlt location));;
 77.51
 val it : unit = ()
let birthday = 18,1,1986
let reverse birth =
let dd,mm,yy = birth
yy,mm,dd
printfn "%A" (reverse birthday)
;;
 (1986, 1, 18)
 val birthday : int * int * int = (18, 1, 1986)
 val reverse : 'a * 'b * 'c -> 'c * 'b * 'a
 val it : unit = ()
'a';;
 val it : char = 'a'
"abc";;
 val it : string = "abc"
10;;
 val it : int = 10
10.4;;
 val it : float = 10.4
val it : float = 10.4
;;
 Unexpected keyword 'val' in interaction at 3,0
 parse error at 3,0
let it : float = 10.4;;
 val it : float = 10.4
it
;;
 val it : float = 10.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment