 	})
 }
 
-public func suchThatOptional<A>(gen: Gen<A>)(p: A -> Bool) -> Gen<Optional<A>> {
-	return sized({ n in
-		return try(gen, 0, max(n, 1), p)
-	})
-}
-
-public func oneOf<A>(gs : [Gen<A>]) -> Gen<A> {
-	assert(gs.count != 0, "oneOf used with empty list")
-
-	return choose((0, gs.count - 1)) >>- ({ x in
-		return gs[x]
-	})
-}
-
 private func pick<A>(n: Int)(lst: [(Int, Gen<A>)]) -> Gen<A> {
 	let (k, x) = lst[0]
 	let tl = Array<(Int, Gen<A>)>(lst[1..<lst.count])

	})
}

public func sized<A>(f: Int -> Gen<A>) -> Gen<A> {
	return Gen(unGen:{ r in
		return { n in

				})
		}
	})
}

/// Constructs a Generator that attempts to generate a values that satisfy a predicate.
///
/// Passing values are wrapped in `.Some`.  Failing values are `.None`.
public func suchThatOptional<A>(gen: Gen<A>)(p: A -> Bool) -> Gen<Optional<A>> {
	return sized({ n in
		return try(gen, 0, max(n, 1), p)
	})
}

/// Randomly selects and uses one of a number of given Generators.
public func oneOf<A>(gs : [Gen<A>]) -> Gen<A> {
	assert(gs.count != 0, "oneOf used with empty list")

	return choose((0, gs.count - 1)) >>- ({ x in
		return gs[x]
	})
}

/// Given a list of Generators and weights associated with them, this function randomly selects and
/// uses a Generator.
public func frequency<A>(xs: [(Int, Gen<A>)]) -> Gen<A> {
	assert(xs.count != 0, "frequency used with empty list")
	
	return choose((1, sum(xs.map() { $0.0 }))) >>- { l in
		return pick(l)(lst: xs)
	}
}

/// Selects a random value from a list and constructs a Generator that returns only that value.
public func elements<A>(xs: [A]) -> Gen<A> {
	assert(xs.count != 0, "elements used with empty list")

	return Gen.fmap({ i in
		return xs[i]
	})(choose((0, xs.count - 1)))
}

/// Takes a list of elements of increasing size, and chooses among an initial segment of the list. 
/// The size of this initial segment increases with the size parameter.
public func growingElements<A>(xs: [A]) -> Gen<A> {
	assert(xs.count != 0, "growingElements used with empty list")

	let k = Double(xs.count)
	return sized({ n in
		return elements(take(max(1, size(k)(m: n)))(xs))
	})
}

/// Generates a list of random length.
public func listOf<A>(gen: Gen<A>) -> Gen<[A]> {
	return sized({ n in
		return choose((0, n)) >>- { k in
			return vectorOf(k)(gen: gen)
		}
	})
}

/// Generates a non-empty list of random length.
public func listOf1<A>(gen: Gen<A>) -> Gen<[A]> {
	return sized({ n in
		return choose((1, max(1, n))) >>- { k in
			return vectorOf(k)(gen: gen)
		}
	})
}

/// Generates a list of a given length.
public func vectorOf<A>(k: Int)(gen : Gen<A>) -> Gen<[A]> {
	return sequence(Array<Gen<A>>(count: k, repeatedValue: gen))
}

/// Implementation Details Follow

private func vary<S : IntegerType>(k : S)(r: StdGen) -> StdGen {
	let s = r.split()
	var gen = ((k % 2) == 0) ? s.0 : s.1
	return (k == (k / 2)) ? gen : vary(k / 2)(r: r)
}

private func try<A>(gen: Gen<A>, k: Int, n : Int, p: A -> Bool) -> Gen<Optional<A>> {
