Created
May 4, 2020 15:22
Revisions
-
steverichey created this gist
May 4, 2020 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ import Cocoa import Foundation protocol AtomType {} struct Atom: AtomType {} func == <Atom1, Atom2> (lhs: Atom1, rhs: Atom2) -> Bool where Atom1: AtomType, Atom2: AtomType { return type(of: lhs) == type(of: rhs) // maybe } func == (lhs: (Atom, Atom), rhs: (Atom, Atom)) -> Bool { return true // ?? } func cons<CarType, CdrType>(_ car: CarType, _ cdr: CdrType) -> (CarType, CdrType) { return (car, cdr) } func car<CarType, CdrType>(_ pair: (CarType, CdrType)) -> CarType { return pair.0 } func cdr<CarType, CdrType>(_ pair: (CarType, CdrType)) -> CdrType { return pair.1 } let ratatouille = Atom() let garlic = Atom() let meal = cons(ratatouille, garlic) let tomato = Atom() let egg = Atom() let omelette = cons(tomato, egg) print(ratatouille == garlic) print(meal == meal) print(ratatouille == car(meal)) print(garlic == cdr(meal)) print(tomato == garlic)