-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Deriver for Data.Vector.Unboxed using Template Haskell
--   
--   A Template Haskell deriver for unboxed vectors, given a pair of
--   coercion functions to and from some existing type with an Unbox
--   instance.
--   
--   Refer to <a>Data.Vector.Unboxed.Deriving</a> for documentation and
--   examples.
@package vector-th-unbox
@version 0.2.1.0


-- | Writing <tt>Unbox</tt> instances for new data types is tedious and
--   formulaic. More often than not, there is a straightforward mapping of
--   the new type onto some existing one already imbued with an
--   <tt>Unbox</tt> instance. The <a>example</a> from the <tt>vector</tt>
--   package represents <tt>Complex a</tt> as pairs <tt>(a, a)</tt>. Using
--   <a>derivingUnbox</a>, we can define the same instances much more
--   succinctly:
--   
--   <pre>
--   derivingUnbox "Complex"
--       [t| (Unbox a) ⇒ Complex a → (a, a) |]    [| \ (r :+ i) → (r, i) |]    [| \ (r, i) → r :+ i |]
--   </pre>
--   
--   Requires the <tt>MultiParamTypeClasses</tt>, <tt>TemplateHaskell</tt>,
--   <tt>TypeFamilies</tt> and probably the <tt>FlexibleInstances</tt>
--   <tt>LANGUAGE</tt> extensions. Note that GHC 7.4 (but not earlier nor
--   later) needs the <a>Vector</a> and <a>MVector</a> class method names
--   to be in scope in order to define the appropriate instances:
--   
--   <pre>
--   #if 706 == 704
--   import qualified Data.Vector.Generic
--   import qualified Data.Vector.Generic.Mutable
--   #endif
--   </pre>
--   
--   Consult the <a>sanity test</a> for a working example.
module Data.Vector.Unboxed.Deriving

-- | Let's consider a more complex example: suppose we want an
--   <tt>Unbox</tt> instance for <tt>Maybe a</tt>. We could encode this
--   using the pair <tt>(Bool, a)</tt>, with the boolean indicating whether
--   we have <tt>Nothing</tt> or <tt>Just</tt> something. This encoding
--   requires a dummy value in the <tt>Nothing</tt> case, necessitating an
--   additional <a>Default</a> constraint. Thus:
--   
--   <pre>
--   derivingUnbox "Maybe"
--       [t| (Default a, Unbox a) ⇒ Maybe a → (Bool, a) |]    [| maybe (False, def) (\ x → (True, x)) |]    [| \ (b, x) → if b then Just x else Nothing |]
--   </pre>
derivingUnbox :: String -> TypeQ -> ExpQ -> ExpQ -> DecsQ
