Skip to content

Instantly share code, notes, and snippets.

func main () {
let typedHeterogeneousList = true =+= "Hello" =+= 1 =+= HNil()
let first: Bool = typedHeterogeneousList.head()
let second: String = typedHeterogeneousList.tail().head()
let third: Int = typedHeterogeneousList.tail().tail().head()
}
protocol HList {
typealias Head
// FILED: rdar://17240493
// Type constraint ignored on function type parameter
//
protocol BoolT {}
class TrueT : BoolT {}
class FalseT : BoolT {}
protocol Nat {
typealias IsZero
@landonf
landonf / 1-README.md
Last active June 2, 2016 06:49
Swift Result Type

A result type (based on swiftz) that can represent either an error or success:

enum Result<X, T> {
  case Err(() -> X)
  case Ok(() -> T)
}

Now we need a way to chain multiple results together without lots of nesting of if statements -- or exceptions. To do so, we can define a new bind (result, next) operator (implementation borrowed from swiftz) that operates on Result types (a.k.a flatMap or >>=):

  • If the result is Err, the result is immediately returned.
@landonf
landonf / example.sil
Created June 5, 2014 14:44
Swift SIL as a compilation target? /Applications/Xcode6-Beta.app/Contents/Developer/usr/bin/xcrun swift -emit-silgen example.swift -module-name MyNameSpace
sil_stage raw
import Builtin
import Swift
enum MyEnum<T> {
case Foo(T)
}
protocol MyProtocol {
@landonf
landonf / 1-XSmallTest-Usage.m
Last active August 29, 2015 14:02
A much nicer single-header XCTest-compatible testing DSL, all in a single header.
#import "XSmallTests.h"
xsm_given("an integer value") {
int v;
xsm_when("the value is 42") {
v = 42;
xsm_then("the value is the answer to the life, the universe, and everything") {
XCTAssertEqual(42, v);
}
@landonf
landonf / CommentPhase.scala
Created June 3, 2014 18:54
Compiler comment phase
/*
* Copyright (c) 2014 Plausible Labs Cooperative, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
@landonf
landonf / AST.scala
Created June 3, 2014 18:53
AST example
/*
* Copyright (c) 2014 Plausible Labs Cooperative, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
@landonf
landonf / example.swift
Created June 3, 2014 15:02
Shorter Class Syntax
class SongEntry (let name: String)
class ExampleWithAdditionalConstructor (let name: String) {
func self () {
self("default name");
}
}
@landonf
landonf / 1-loop.swift
Last active August 29, 2015 14:02
Swift vs Scala, FIGHT
// Example totally stolen from Mike Ash
1> func lameFor(count: Int, body: @auto_closure () -> ()) { for _ in 0..count { body() } }
2>
3> lameFor(3, println("I'm the greetest"))
I'm the greetest
I'm the greetest
I'm the greetest
@landonf
landonf / library_quality.md
Created April 1, 2014 21:10
An addendum to issue #1852

Social + Tool Driven Quality Control

The follow-up I wrote for CocoaPods issue #1852 covers a lot of technical ground, but I also wanted to tackle the issue from a less crash reporting-focused perspective.

While I think the technical direction is interesting, and we're exploring some of these ideas in PLCrashReporter, it's easy to lose sight of the original goal -- ensuring that CocoaPod users can introduce library dependencies without concern that there are significant regressions in a given library or release.

In this area, I think that social and tool-driven hints are not only cheaper to implement, but would be just as powerful -- if not more so -- than a complex crash reporting system that can only find issues after they've already shipped.

If you look at automated build and dependency tooling on other platforms (in particular, I have Maven since that's what I'm familiar with, but these notions are hardly unique to the JVM language family),