We present a new, Bayesian method for inferring haplotypes for unphased genotypes. The method can be viewed as a unification
of some ideas of variable-order Markov chain modelling and ensemble learning that so far have been implemented only separately
in some of the state-of-the-art methods. Specifically, we make use of the Context Tree Weighting algorithm to efficiently
compute the posterior probability of any given haplotype assignment; we employ a simulated annealing scheme to rapidly find
several local optima of the posterior; and we sketch a full Bayesian analogue, in which a weighted sample of haplotype assignments
is drawn to summarize the posterior distribution. We also show that one can minimize in linear time the average switch distance,
a popular measure of phasing accuracy, to a given (weighted) sample of haplotype assignments. We demonstrate empirically that
the presented method typically performs as well as the leading fast haplotype inference methods, and sometimes better. The
methods are freely available in a computer program BACH (Bayesian Context-based Haplotyping)