This file contains hidden or 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 characters
// Thanks, Chris Eidhof for the idea | |
struct Monoid<T> { | |
let empty: T | |
let append: (T, T) -> T | |
func fold(arr: Array<T>) -> T { | |
return arr.reduce(self.empty, self.append) | |
} | |
} |
This file contains hidden or 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 characters
/* | |
* A callback-base implementation of effectful computation that defers interpretation | |
* until after computation is expressed (so you can inject different interpreters | |
* onto the same computation). | |
* | |
* The downside is the results aren't expressed as values. They are callback calls. | |
* You probably don't actually want to use this, but it seems interesting to think about. | |
* | |
* Inspired by "Programming with Algebraic Effects and Handlers" by | |
* Andrej Bauer and Matija Pretnar 2012 |
This file contains hidden or 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 characters
// An exploration of http://okmij.org/ftp/tagless-final/sharing/sharing.pdf | |
// Specifically focusing on Hashconsing and Sklansky | |
typealias NodeId = Int | |
enum Node: Equatable, Hashable { | |
case nconst(Int) | |
case nvar(String) | |
case nadd(NodeId, NodeId) | |
var hashValue: Int { |
This file contains hidden or 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 characters
// Algorithm W | |
// From Principal Types for functional programs | |
// http://web.cs.wpi.edu/~cs4536/c12/milner-damas_principal_types.pdf | |
// by bkase | |
// STD library | |
infix operator <>: AdditionPrecedence | |
extension Dictionary { | |
static func <>(lhs: Dictionary, rhs: Dictionary) -> Dictionary { | |
var d: [Key: Value] = [:] |
This file contains hidden or 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 characters
// Write some awesome Swift code, or import libraries like "Foundation", | |
// "Dispatch", or "Glibc" | |
enum Result<E, T> { | |
case fail(E) | |
case success(T) | |
var succeeded: Bool { | |
switch self { | |
case .fail(_): return false |
This file contains hidden or 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 characters
// Paper located: https://github.com/snowleopard/alga-paper | |
infix operator <>: AdditionPrecedence | |
protocol Semigroup { | |
static func <>(lhs: Self, rhs: Self) -> Self | |
} | |
protocol Monoid: Semigroup { | |
static var empty: Self { get } | |
} | |
protocol CommutativeMonoid: Monoid { } | |
protocol BoundedSemilattice: CommutativeMonoid { } |
This file contains hidden or 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 characters
protocol Base { } | |
extension Base { | |
var a: String? { return nil } | |
var b: Int? { return nil } | |
} | |
protocol A: Base { | |
var a: String { get } | |
} |
This file contains hidden or 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 characters
module Example { | |
type jsProps = {. x: int, y: string }; | |
type state = ReasonReact.stateless; | |
type props = ReasonReact.noRetainedProps; | |
type action = ReasonReact.actionless; | |
let component = ReasonReact.statelessComponent("Example"); | |
let make = (jsThis: Withjs.thisType) => (~x, ~y) => (_children) => { |
This file contains hidden or 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 characters
// SUPER ROUGH ideas about distributive property on Animations | |
// This is the "current relative time as input" rather than the "0 to 1 as input" (unit) version of the animation | |
// this has flaws, but simple to show (or not) the distributive property of sequence and parallel | |
infix operator <>: AdditionPrecedence | |
protocol Semigroup { | |
static func <>(lhs: Self, rhs: Self) -> Self | |
} | |
indirect enum FreeSemigroup<A>: Semigroup { |
This file contains hidden or 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 characters
// An exploration of http://okmij.org/ftp/tagless-final/sharing/sharing.pdf | |
// Specifically focusing on Hashconsing and Sklansky | |
// See http://swift.sandbox.bluemix.net/#/repl/5940bd55698d8d064dec2b22 for this snippet in a playground | |
typealias NodeId = Int | |
enum Node: Equatable, Hashable { | |
case nconst(Int) | |
case nvar(String) | |
case nadd(NodeId, NodeId) |