Instantly share code, notes, and snippets.

@Szer /list.fsx
Created Aug 18, 2017

Embed
What would you like to do?
example of immutable list in F#
let a = new obj();
let b = new obj();
let c = new obj();
a.Equals(b) // <- false
b.Equals(c) // <- false
c.Equals(a) // <- false
let aList = [a] // <- [System.Object]
let bList = [b] // <- [System.Object]
let cList = [c] // <- [System.Object]
let abList = aList @ bList // <- [System.Object; System.Object]
abList.Head.Equals(a) // <- true
abList.Tail.Head.Equals(b) // <- true
let abcList = abList @ cList // <- [System.Object; System.Object; System.Object]
abcList.Head.Equals(a) // <- true
abcList.Tail.Head.Equals(b) // <- true
abcList.Tail.Tail.Head.Equals(c) // <- true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment