Skip to content

Instantly share code, notes, and snippets.

This is a literate Haskell file that describes the sketch of a type-safe URL
handling system. It is not done (or anything near it), but is intended as
inspiration for a complete system.
First we will show some examples, and later we will implement the library. The
library uses the |regular| package for generic programming (cabal install regular).
> {-# LANGUAGE TemplateHaskell, TypeFamilies, EmptyDataDecls,
> TypeSynonymInstances, TypeOperators, ScopedTypeVariables #-}
>
> {-# LANGUAGE GADTs, TypeOperators, TupleSections #-}
> module Routing2 where
> import Control.Applicative hiding (many, (<|>))
> import Text.ParserCombinators.Parsec.Prim
> import Text.ParserCombinators.Parsec.Error
> import Text.ParserCombinators.Parsec.Char
> import Text.ParserCombinators.Parsec.Combinator
> import Data.List (intercalate)
import Cocoa
enum CoroutineState {
case Fresh, Running, Blocked, Canceled, Done
}
struct CoroutineCancellation: ErrorType {}
class CoroutineImpl<InputType, YieldType> {
let body: (yield: YieldType throws -> InputType) throws -> Void
protocol WebClient { }
class WebClientImpl: WebClient {
}
class VMOne {
var client: WebClient
var prop: Int
init(client: WebClient, prop: Int) {
@chriseidhof
chriseidhof / qsort.m
Last active September 17, 2015 10:07
qsort
#import <Foundation/Foundation.h>
int stringComp(const void *a, const void *b) {
NSString *aO = *(NSString *__autoreleasing*)a;
NSString *bO = *(NSString *__autoreleasing*)b;
return [aO caseInsensitiveCompare:bO];
}
{-# LANGUAGE OverloadedStrings, TemplateHaskell, EmptyDataDecls, TypeFamilies #-}
module Main where
import Debug.Trace (trace)
import Happstack.Server
import Web.Routes.Site
import Web.Routes.PathInfo (PathInfo (..), parseSegments)
import Web.Routes.Happstack
Digestive functors
==================
CE: Misschien iets over HTML forms genereren? Dit is wellicht iets te abstract. Ook dat je controle hebt over error-correction en dat het composable is? Misschien uitleggen dat het een alternatief voor formlets is dat strikt beter is?
Digestive functors is a library that provides an abstract interface towards
input consumption. The interface is based on applicative functors.
> {-# LANGUAGE OverloadedStrings #-}
> import Text.Digestive
@chriseidhof
chriseidhof / parallelMap.swift
Last active September 25, 2015 12:44
no-escape.swift
extension Array {
func parallelMap<U>(transform: Element -> U) -> [U] {
var result: [U?] = Array<U?>(count: count, repeatedValue: nil)
dispatch_apply(count, dispatch_get_global_queue(0, 0)) {
result[$0] = transform(self[$0])
}
return result.map { $0! }
}
}
@chriseidhof
chriseidhof / TilingView.h
Created December 8, 2011 17:50
TilingView
#import <UIKit/UIKit.h>
typedef UIImage*(^getTile)(CGFloat scale, int row, int col);
@interface TilingView : UIView {
getTile getTile;
}
- (id)initWithSize:(CGSize)size levelsOfDetail:(NSInteger)levelsOfDetail tileSize:(CGSize)tileSize;
@property (nonatomic,copy) getTile getTile;
// This accompanies http://chris.eidhof.nl/posts/repmin-in-swift.html
import UIKit
// Unfortunately, we need Box
public class Box<T> {
public let unbox: T
public init(_ value: T) { self.unbox = value }
}