#Every Single Option Under The Sun
- optimization level options
- automatic crashing options
- debug info options
- swift internal options
- swift debug/development internal options
- linker-specific options
- mode options
#Every Single Option Under The Sun
// Playground - noun: a place where people can play | |
public func id<A>(x : A) -> A { | |
return x | |
} | |
public func error<A>(x : String) -> A { | |
assert(false, x) | |
} |
public func unsafeCoerce<A, B>(_ x : A) -> B { | |
return unsafeBitCast(x, to: B.self) | |
} | |
func Y<A>(_ f : @escaping (A) -> A) -> A { | |
return { (x : @escaping (A) -> A) in | |
return f((x(unsafeCoerce(x)))) | |
}({ (x : A) -> A in | |
let fn : (A) -> A = unsafeCoerce(x) | |
return f(fn(x)) |
Copy and paste the swift code below into a playground to experiment.
This is a very close emulation of Functor and Monad typeclasses in swift. As of Swift 1.2 and Xcode 6.3, this is no longer very fragile.
Unfortunately, the compiler cannot verify the types when passing a function to (>>=)
. We have to wrap the function in a closure and call it with an explicit argument to compile.
optionalDoubles >>= squareRoot // doesn't compile
optionalDoubles >>= { squareRoot($0) } // compiles
Copy and paste the swift code below into a playground to experiment.
This is a very close emulation of Functor and Monad typeclasses in swift. However, it is very fragile (i.e. easy to crash the compiler).
For example, instance methods of fmap
will run fine, but attempting to use a globally defined fmap
that acts on Functor
types will cause a crash. Similarly for bind
. Unfortunately this means we cannot define the nice infix operator versions of these functions.
protocol Functor { | |
func fmap <A, B> (Self<A>, A -> B) -> Self<B> | |
// ^ ERROR: Cannot specialize non-generic type '`Self`' | |
} | |
enum Maybe<A> : Functor { | |
case Nothing | |
case Just(A) | |
func fmap<B>(x: Maybe<A>, f: A -> B) -> Maybe<B> { |
// | |
// Yoneda.swift | |
// Basis | |
// | |
// Created by Robert Widmann on 12/11/14. | |
// Copyright (c) 2014 Robert Widmann. All rights reserved. | |
// | |
import Basis |
Write a program that calculates purchase price for movie tickets using any language you like. It should not be a full-blown web app; it can be a simple class or collection of methods invokable by your test suite. We'll provide you with some requirements, test-cases, and even a sample interface - all you have to do is give us some software.
The Base Admission Rate cover movies to be viewed on a regular weekday (see "Special Movie Day" below), in 2D, with a length of <= 120 minutes, viewed from the main seating area (there is also a balcony seating area, which is much fancier).
It is seductive to imagine that effect handlers in an algebraic effect system are not part of the program itself but metalanguage-level folds over the program tree. And in traditional free-like formulations, this is in fact the case. The Eff
monad represents the program tree, which has only two cases:
data Eff effs a where
Pure :: a -> Eff effs a
Op :: Op effs a -> (a -> Eff effs b) -> Eff effs b
data Op effs a where
The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).
My take-aways are:
You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.
Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse