The Quipper System

Safe HaskellNone

Quipper.Internal

Contents

Description

This module exposes interfaces that are internal to Quipper, and are not intended for use by user-level code, but may be useful in libraries that extend Quipper's functionality.

This module must not be imported directly by user-level code. It may, however, be imported by libraries. A typical use of this module is in a library that defines a new kind of QCData.

Synopsis

Quantum data

The module Quipper.Internal.QData provides type classes for dealing with various "shaped" quantum and classical data structures. Please see Quipper.Internal.QData for documentation.

Currying

class QCurry fun args res | fun -> args res, args res -> fun where Source #

The QCurry type class is similar to the Curry type class, except that the result type is guarded by the Circ monad. It provides a family of type isomorphisms

fun  ≅  args -> Circ res,

where

fun = a1 -> a2 -> ... -> an -> Circ res,
args = (a1, (a2, (..., (an, ())))).

The benefit of having Circ in the result type is that it ensures that the result type is not itself a function type, and therefore fun has a unique arity n. Then args and res are uniquely determined by fun, which can be used to write higher-order operators that consume fun of any arity and "do the right thing".

Methods

qcurry :: (args -> Circ res) -> fun Source #

quncurry :: fun -> args -> Circ res Source #

Instances
QCurry (Circ b) () b # 
Instance details

Defined in Quipper.Internal.Generic

Methods

qcurry :: (() -> Circ b) -> Circ b Source #

quncurry :: Circ b -> () -> Circ b Source #

QCurry fun args res => QCurry (a -> fun) (a, args) res # 
Instance details

Defined in Quipper.Internal.Generic

Methods

qcurry :: ((a, args) -> Circ res) -> a -> fun Source #

quncurry :: (a -> fun) -> (a, args) -> Circ res Source #

Error handlers

type ErrMsg = String -> String Source #

Often a low-level function, such as qcdata_zip or qcdata_promote, throws an error because of a failure of some low-level condition, such as "list too short". To produce error messages that are meaningful to user-level code, these functions do not have a hard-coded error message. Instead, they input a stub error message.

A meaningful error message typically consists of at least three parts:

  • the name of the user-level function where the error occurred, for example: "reverse_generic";
  • what the function was doing when the error occurred, for example: "operation not permitted in reversible circuit";
  • a specific low-level reason for the error, for example: "dynamic lifting".

Thus, a meaningful error message may be: "reverse_generic: operation not permitted in reversible circuit: dynamic lifting".

The problem is that the three pieces of information are not usually present in the same place. The user-level function is often a wrapper function that performs several different mid-level operations (e.g., transforming, reversing). The mid-level function knows what operation was being performed when the error occurred, but often calls a lower-level function to do the actual work (e.g., encapsulating).

Therefore, a stub error message is a function that inputs some lower-level reason for a failure (example: "list too short") and translates this into a higher-level error message (example: "qterm: shape of parameter does not data: list too short").

Sometimes, the stub error message may also ignore the low-level message and completely replace it by a higher-level one. For example, a function that implements integers as bit lists may wish to report a problem with integers, rather than a problem with the underlying lists.

The Labelable class

class Labelable a s where Source #

Labelable a s means that a is a data structure that can be labelled with the format s. A "format" is a string, or a data structure with strings at the leaves.

Methods

label_rec :: a -> s -> LabelMonad () Source #

Recursively label a data structure with the given format.

Instances
Labelable Char String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: Char -> String -> LabelMonad () Source #

Labelable Double String # 
Instance details

Defined in Quipper.Internal.Labels

Labelable Float String # 
Instance details

Defined in Quipper.Internal.Labels

Labelable Int String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: Int -> String -> LabelMonad () Source #

Labelable Integer String # 
Instance details

Defined in Quipper.Internal.Labels

Labelable () () # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: () -> () -> LabelMonad () Source #

Labelable () String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: () -> String -> LabelMonad () Source #

Labelable Bit String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: Bit -> String -> LabelMonad () Source #

Labelable Qubit String # 
Instance details

Defined in Quipper.Internal.Labels

Labelable a String => Labelable [a] String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: [a] -> String -> LabelMonad () Source #

Labelable a String => Labelable (Signed a) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: Signed a -> String -> LabelMonad () Source #

QCLeaf x => Labelable (XInt x) String # 
Instance details

Defined in Quipper.Libraries.Arith

Methods

label_rec :: XInt x -> String -> LabelMonad () Source #

Labelable a s => Labelable [a] [s] # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: [a] -> [s] -> LabelMonad () Source #

Labelable a String => Labelable (Signed a) (Signed String) # 
Instance details

Defined in Quipper.Internal.Labels

(Labelable a String, Labelable b String) => Labelable (a, b) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b) -> String -> LabelMonad () Source #

(Labelable a String, Labelable b String) => Labelable (B_Endpoint a b) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: B_Endpoint a b -> String -> LabelMonad () Source #

(Labelable a sa, Labelable b sb) => Labelable (a, b) (sa, sb) # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b) -> (sa, sb) -> LabelMonad () Source #

(Labelable a s, Labelable b t) => Labelable (B_Endpoint a b) (B_Endpoint s t) # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: B_Endpoint a b -> B_Endpoint s t -> LabelMonad () Source #

(Labelable a String, Labelable b String, Labelable c String) => Labelable (a, b, c) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c) -> String -> LabelMonad () Source #

(Labelable a sa, Labelable b sb, Labelable c sc) => Labelable (a, b, c) (sa, sb, sc) # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c) -> (sa, sb, sc) -> LabelMonad () Source #

(Labelable a String, Labelable b String, Labelable c String, Labelable d String) => Labelable (a, b, c, d) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d) -> String -> LabelMonad () Source #

(Labelable a sa, Labelable b sb, Labelable c sc, Labelable d sd) => Labelable (a, b, c, d) (sa, sb, sc, sd) # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d) -> (sa, sb, sc, sd) -> LabelMonad () Source #

(Labelable a String, Labelable b String, Labelable c String, Labelable d String, Labelable e String) => Labelable (a, b, c, d, e) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e) -> String -> LabelMonad () Source #

(Labelable a sa, Labelable b sb, Labelable c sc, Labelable d sd, Labelable e se) => Labelable (a, b, c, d, e) (sa, sb, sc, sd, se) # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e) -> (sa, sb, sc, sd, se) -> LabelMonad () Source #

(Labelable a String, Labelable b String, Labelable c String, Labelable d String, Labelable e String, Labelable f String) => Labelable (a, b, c, d, e, f) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e, f) -> String -> LabelMonad () Source #

(Labelable a sa, Labelable b sb, Labelable c sc, Labelable d sd, Labelable e se, Labelable f sf) => Labelable (a, b, c, d, e, f) (sa, sb, sc, sd, se, sf) # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e, f) -> (sa, sb, sc, sd, se, sf) -> LabelMonad () Source #

(Labelable a String, Labelable b String, Labelable c String, Labelable d String, Labelable e String, Labelable f String, Labelable g String) => Labelable (a, b, c, d, e, f, g) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e, f, g) -> String -> LabelMonad () Source #

(Labelable a sa, Labelable b sb, Labelable c sc, Labelable d sd, Labelable e se, Labelable f sf, Labelable g sg) => Labelable (a, b, c, d, e, f, g) (sa, sb, sc, sd, se, sf, sg) # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e, f, g) -> (sa, sb, sc, sd, se, sf, sg) -> LabelMonad () Source #

(Labelable a String, Labelable b String, Labelable c String, Labelable d String, Labelable e String, Labelable f String, Labelable g String, Labelable h String) => Labelable (a, b, c, d, e, f, g, h) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e, f, g, h) -> String -> LabelMonad () Source #

(Labelable a sa, Labelable b sb, Labelable c sc, Labelable d sd, Labelable e se, Labelable f sf, Labelable g sg, Labelable h sh) => Labelable (a, b, c, d, e, f, g, h) (sa, sb, sc, sd, se, sf, sg, sh) # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e, f, g, h) -> (sa, sb, sc, sd, se, sf, sg, sh) -> LabelMonad () Source #

(Labelable a String, Labelable b String, Labelable c String, Labelable d String, Labelable e String, Labelable f String, Labelable g String, Labelable h String, Labelable i String) => Labelable (a, b, c, d, e, f, g, h, i) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e, f, g, h, i) -> String -> LabelMonad () Source #

(Labelable a sa, Labelable b sb, Labelable c sc, Labelable d sd, Labelable e se, Labelable f sf, Labelable g sg, Labelable h sh, Labelable i si) => Labelable (a, b, c, d, e, f, g, h, i) (sa, sb, sc, sd, se, sf, sg, sh, si) # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e, f, g, h, i) -> (sa, sb, sc, sd, se, sf, sg, sh, si) -> LabelMonad () Source #

(Labelable a String, Labelable b String, Labelable c String, Labelable d String, Labelable e String, Labelable f String, Labelable g String, Labelable h String, Labelable i String, Labelable j String) => Labelable (a, b, c, d, e, f, g, h, i, j) String # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e, f, g, h, i, j) -> String -> LabelMonad () Source #

(Labelable a sa, Labelable b sb, Labelable c sc, Labelable d sd, Labelable e se, Labelable f sf, Labelable g sg, Labelable h sh, Labelable i si, Labelable j sj) => Labelable (a, b, c, d, e, f, g, h, i, j) (sa, sb, sc, sd, se, sf, sg, sh, si, sj) # 
Instance details

Defined in Quipper.Internal.Labels

Methods

label_rec :: (a, b, c, d, e, f, g, h, i, j) -> (sa, sb, sc, sd, se, sf, sg, sh, si, sj) -> LabelMonad () Source #

with_index :: String -> LabelMonad () -> LabelMonad () Source #

Run a subcomputation with a subscript index appended to the current index list. Sample usage:

with_index "0" $ do
  <<<labelings>>>

with_dotted_index :: String -> LabelMonad () -> LabelMonad () Source #

Run a subcomputation with a dotted index appended to the current index list. Sample usage:

with_dotted_index "left" $ do
  <<<labelings>>>

indexed :: LabelMonad () -> String -> LabelMonad () Source #

Like with_index, except the order of the arguments is reversed. This is intended to be used as an infix operator:

<<<labeling>>> `indexed` "0"

dotted_indexed :: LabelMonad () -> String -> LabelMonad () Source #

Like with_dotted_index, except the order of the arguments is reversed. This is intended to be used as an infix operator:

<<<labeling>>> `dotted_indexed` "left"

Functions for IntMaps

intmap_zip :: IntMap x -> IntMap y -> IntMap (x, y) Source #

Take two IntMaps with the same domain, and form a new IntMap whose values are pairs. It is an error if the two inputs don't have identical domains.

intmap_zip_errmsg :: IntMap x -> IntMap y -> String -> IntMap (x, y) Source #

Like intmap_zip, but also takes an error message to use in case of domain mismatch.

intmap_map :: (x -> y) -> IntMap x -> IntMap y Source #

Map a function over all values in an IntMap.

intmap_mapM :: Monad m => (x -> m y) -> IntMap x -> m (IntMap y) Source #

Monadic version of intmap_map. Map a function over all values in an IntMap.

Identity types

data Identity a b Source #

The type Identity a b witnesses the fact that a and b are the same type. In other words, this type is non-empty if and only if a = b. This property is not guaranteed by the type system, but by the API, via the fact that the operators reflexivity, symmetry, and transitivity are the only exposed constructors for this type. The implementation of this type is deliberately hidden, as this is the only way to guarantee its defining property.

Identity types are useful in certain situations. For example, they can be used to define a data type which is polymorphic in some type variable x, and which has certain constructors that are only available when x is a particular type. For example, in the declaration

data ExampleType x = Constructor1 x | Constructor2 x (Identity x Bool),

Constructor1 is available for all x, but Constructor2 is only available when x = Bool.

Instances
Show (Identity a b) # 
Instance details

Defined in Quipper.Utils.Auxiliary

Methods

showsPrec :: Int -> Identity a b -> ShowS #

show :: Identity a b -> String #

showList :: [Identity a b] -> ShowS #

reflexivity :: Identity a a Source #

Witness the fact that a=a.

symmetry :: Identity a b -> Identity b a Source #

Witness the fact that a=b implies b=a.

transitivity :: Identity a b -> Identity b c -> Identity a c Source #

Witness the fact that a=b and b=c implies a=c.

identity :: Identity a b -> a -> b Source #

The identity function id : ab, provided that a and b are the same type.