derive-2.6.5/ 0000755 0000000 0000000 00000000000 07346545000 011173 5 ustar 00 0000000 0000000 derive-2.6.5/CHANGES.txt 0000644 0000000 0000000 00000004012 07346545000 013001 0 ustar 00 0000000 0000000 2.6.4
Rewrite for haskell-src-exts == 1.20.*
#27, disable a few more extensions by default (sync with the HLint list)
2.6.3
#24, support GHC 8.2
2.6.2
#19, more upgrade bug fixes
2.6.1
#19, allow haskell-src-exts-1.19
2.6
Remove lots of derivations that didn't seem useful (Eq, Show etc)
Change to use annotated Haskell syntax trees
Require haskell-src-exts-1.18
2.5.26
#17, fix incomplete pattern matches for certain types of data
2.5.25
#14, further GHC 8.0.1 updates
2.5.24
#14, update to GHC 8.0.1
#15, move all the source files under src to speed up building
Delete the FixedPpr module, was unused
2.5.23
Require haskell-src-exts-1.17
2.5.22
#7, #8 convert more types from TemplateHaskell
2.5.21
Fix the homepage link
2.5.20
#5, fix regression with higher-kinded constructors becoming context
2.5.19
Support GHC 7.10
2.5.18
#4, fix the read instance for nullary constructors
2.5.17
Upgrade to haskell-src-exts-1.16
Remove GHC 7.2 support
2.5.16
Allow transformers-0.4 and above
2.5.15
Allow haskell-src-exts-1.15.*
2.5.14
#3, support GHC 7.9
2.5.13
#622, turn on more Haskell extensions
2.5.12
Upgrade to haskell-src-exts-1.14.*
2.5.11
Support GHC 7.6
2.5.10
Add derivation for Lens
Modify the Typeable derivation to use mkTyCon3
2.5.9
Support the Template Haskell Unpacked constructor
2.5.8
Allow haskell-src-exts-1.13.*
2.5.7
Allow haskell-src-exts-1.12.*
2.5.6
Update the copyright year
Allow transformers-0.3.*
2.5.5
#513, allow derive to be run as a preprocessor
Improve the documentation for UniplateDirect
2.5.4
#394, allow tuple names in more places
Fix error when deriving Binary on "data A = B"
2.5.3
GHC 7.2 compatibility
2.5.2
Relax the dependency on haskell-src-exts to < 1.12
2.5.1
Improve documentation for deriveMain
2.5
#257, add Data.DeriveMain.deriveMain, to allow user derivations
2.4.2
Relax the dependency on haskell-src-exts to < 1.11
Start of changelog
derive-2.6.5/LICENSE 0000644 0000000 0000000 00000002764 07346545000 012211 0 ustar 00 0000000 0000000 Copyright Neil Mitchell 2006-2017.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Neil Mitchell nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
derive-2.6.5/Main.hs 0000644 0000000 0000000 00000000166 07346545000 012416 0 ustar 00 0000000 0000000
module Main(main) where
import Data.Derive.All
import Data.DeriveMain
main :: IO ()
main = deriveMain derivations
derive-2.6.5/README.md 0000644 0000000 0000000 00000026052 07346545000 012457 0 ustar 00 0000000 0000000 # Derive [](https://hackage.haskell.org/package/derive) [](https://travis-ci.org/ndmitchell/derive)
**Warning: This package has no official maintainer anymore. Use at your own risk. You may wish to consider the built-in mechanism [`GHC.Generics`](https://hackage.haskell.org/package/base-4.11.1.0/docs/GHC-Generics.html) or libraries such as [`generic-deriving`](https://hackage.haskell.org/package/generic-deriving).**
Data.Derive is a library and a tool for deriving instances for Haskell programs. It is designed to work with custom derivations, SYB and Template Haskell mechanisms. The tool requires GHC, but the generated code is portable to all compilers. We see this tool as a competitor to DrIFT.
This document proceeds as follows:
* Obtaining and Installing Data.Derive
* Supported Derivations
* Using the Derive Program
* Using Template Haskell Derivations
* Writing a New Derivation
### Acknowledgements
Thanks to everyone who has submitted patches and given assistance, including: Twan van Laarhoven, Spencer Janssen, Andrea Vezzosi, Samuel Bronson, Joel Raymont, Benedikt Huber, Stefan O'Rear, Robin Green, Bertram Felgenhauer.
## Obtaining and Installing Data.Derive
Installation follows the standard pattern of any Haskell library or program, type cabal update to update your local hackage database, then cabal install derive to install Derive.
## Supported Derivations
Data.Derive is not limited to any prebuild set of derivations, see later for howto add your own. Out of the box, we provide instances for the following libraries.
* **[Arbitrary](http://hackage.haskell.org/packages/archive/QuickCheck/latest/doc/html/Test-QuickCheck.html#t%3AArbitrary)** - from the library [QuickCheck](http://hackage.haskell.org/package/QuickCheck)
* **[ArbitraryOld](http://hackage.haskell.org/packages/archive/QuickCheck/1.2.0.0/doc/html/Test-QuickCheck.html#t%3AArbitraryOld)** - from the library [QuickCheck-1.2.0.0](http://hackage.haskell.org/package/QuickCheck-1.2.0.0)
* **[Arities](http://hackage.haskell.org/packages/archive/derive/latest/doc/html/Data-Derive-Class-Arities.html#t%3AArities)** - from the library [derive](http://hackage.haskell.org/package/derive)
* **[Binary](http://hackage.haskell.org/packages/archive/binary/latest/doc/html/Data-Binary.html#t%3ABinary)** - from the library [binary](http://hackage.haskell.org/package/binary)
* **[BinaryDefer](http://hackage.haskell.org/packages/archive/binarydefer/latest/doc/html/Data-Binary-Defer.html#t%3ABinaryDefer)** - from the library [binarydefer](http://hackage.haskell.org/package/binarydefer)
* **[Bounded](http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#t%3ABounded)** - from the library [base](http://hackage.haskell.org/package/base)
* **[DataAbstract](http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Data.html#t%3ADataAbstract)** - from the library [base](http://hackage.haskell.org/package/base)
* **[Default](http://hackage.haskell.org/packages/archive/derive/latest/doc/html/Data-Derive-Class-Default.html#t%3ADefault)** - from the library [derive](http://hackage.haskell.org/package/derive)
* **[EnumCyclic](http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#t%3AEnum)** - from the library [base](http://hackage.haskell.org/package/base)
* **[Fold](http://hackage.haskell.org/packages/archive/derive/latest/doc/html/Data-Derive-Fold.html)**
* **[From](http://hackage.haskell.org/packages/archive/derive/latest/doc/html/Data-Derive-From.html)**
* **[Has](http://hackage.haskell.org/packages/archive/derive/latest/doc/html/Data-Derive-Has.html)**
* **[Is](http://hackage.haskell.org/packages/archive/derive/latest/doc/html/Data-Derive-Is.html)**
* **[JSON](http://hackage.haskell.org/packages/archive/json/latest/doc/html/Text-JSON.html#t%3AJSON)** - from the library [json](http://hackage.haskell.org/package/json)
* **[LazySet](http://hackage.haskell.org/packages/archive/derive/latest/doc/html/Data-Derive-LazySet.html)**
* **[Lens](http://hackage.haskell.org/packages/archive/data/lens/doc/html/Data-Lens-Common.html#t%3ALens)** - from the library [data-lens](http://hackage.haskell.org/package/data-lens)
* **[Monoid](http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Monoid.html#t%3AMonoid)** - from the library [base](http://hackage.haskell.org/package/base)
* **[NFData](http://hackage.haskell.org/packages/archive/deepseq/latest/doc/html/Control-DeepSeq.html#t%3ANFData)** - from the library [deepseq](http://hackage.haskell.org/package/deepseq)
* **[Ref](http://hackage.haskell.org/packages/archive/derive/latest/doc/html/Data-Derive-Ref.html)**
* **[Serial](http://hackage.haskell.org/packages/archive/smallcheck/latest/doc/html/Test-SmallCheck.html#t%3ASerial)** - from the library [smallcheck](http://hackage.haskell.org/package/smallcheck)
* **[Serialize](http://hackage.haskell.org/packages/archive/cereal/latest/doc/html/Data-Serialize.html#t%3ASerialize)** - from the library [cereal](http://hackage.haskell.org/package/cereal)
* **[Set](http://hackage.haskell.org/packages/archive/derive/latest/doc/html/Data-Derive-Set.html)**
* **[UniplateDirect](http://hackage.haskell.org/packages/archive/uniplate/latest/doc/html/Data-Generics-Uniplate-Direct.html#t%3AUniplateDirect)** - from the library [uniplate](http://hackage.haskell.org/package/uniplate)
* **[UniplateTypeable](http://hackage.haskell.org/packages/archive/uniplate/latest/doc/html/Data-Generics-Uniplate-Typeable.html#t%3AUniplateTypeable)** - from the library [uniplate](http://hackage.haskell.org/package/uniplate)
* **[Update](http://hackage.haskell.org/packages/archive/derive/latest/doc/html/Data-Derive-Update.html)**
## Using the Derive program
Let's imagine we've defined a data type:
data Color = RGB Int Int Int
| CMYK Int Int Int Int
deriving (Eq, Show)
Now we wish to extend this to derive Binary and change to defining Eq using our library. To do this we simply add to the deriving clause.
data Color = RGB Int Int Int
| CMYK Int Int Int Int
deriving (Show {-! Eq, Binary !-})
Or alternatively write:
{-!
deriving instance Eq Color
deriving instance Binary Color
!-}
Now running derive on the program containing this code will generate appropriate instances. How do you combine these instances back into the code? There are various mechanisms supported.
### Appending to the module
One way is to append the text to the bottom of the module, this can be done by passing the --append flag. If this is done, Derive will generate the required instances and place them at the bottom of the file, along with a checksum. Do not modify these instances.
### As a GHC preprocessor
To use Derive as a GHC preprocessor, add the following line at the top of the source file:
{-# OPTIONS_GHC -F -pgmFderive -optF-F #-}
This instructs GHC to apply a preprocessor (-F), and to use the preprocessor derive -F.
### Using CPP
One way is to use CPP. Ensure your compiler is set up for compiling with the C Pre Processor. For example:
{-# LANGUAGE CPP #-}
{-# OPTIONS_DERIVE --output=file.h #-}
module ModuleName where
#include "file.h"
### Side-by-side Modules
If you had Colour.Type, and wished to place the Binary instance in Colour.Binary, this can be done with:
{-# OPTIONS_DERIVE --output=Binary.hs --module=Colour.Binary --import #-}
Here you ask for the output to go to a particular file, give a specific module name and import this module. This will only work if the data structure is exported non-abstractly.
## Using Template Haskell Derivations
One of Derive's advantages over DrIFT is support for Template Haskell (abbreviated TH). Derive can be invoked automatically during the compilation process, and transparently supports deriving across module boundaries. The main disadvantage of TH-based deriving is that it is only portable to compilers that support TH; currently that is GHC only.
To use the TH deriving system, with the same example as before:
{-# LANGUAGE TemplateHaskell #-}
import Data.DeriveTH
import Data.Binary
data Color = RGB Int Int Int
| CMYK Int Int Int Int
deriving (Show)
$( derive makeEq ''Color )
$( derive makeBinary ''Color )
We need to tell the compiler to insert the instance using the TH splice construct, $( ... ) (the spaces are optional). The splice causes the compiler to run the function derive (exported from Data.DeriveTH), passing arguments makeFooBar and ''Color. The second argument deserves more explanation; it is a quoted symbol, somewhat like a quoted symbol in Lisp and with deliberately similar syntax. (Two apostrophes are used to specify that this name is to be resolved as a type constructor; just 'Color would look for a data constructor named Color.)
## Writing a New Derivation
There are two methods for writing a new derivation, guessing or coding. The guessing method is substantially easier if it will work for you, but is limited to derivations with the following properties:
* Inductive - each derivation must be similar to the previous one. Binary does not have this property as a 1 item derivation does not have a tag, but a 2 item derivation does.
* Not inductive on the type - it must be an instance for the constructors, not for the type. Typeable violates this property by inducting on the free variables in the data type.
* Not type based - the derivation must not change based on the types of the fields. Play and Functor both behave differently given differently typed fields.
* Not record based - the derivation must not change on record fields. Show outputs the fields, so this is not allowed.
If however your instance does meet these properties, you can use derivation by guess. Many instances do meet these conditions, for examples see: Eq, Ord, Data, Serial etc. If however you need to code the derivation manually see examples such as Update and Functor.
### Modifying Derive
The standard sequence for testing Derive is:
$ ghci Main.hs
:main --generate
:reload
:main --test
The `--generate` option will automatically generate DSL's for derivations derived by example. The `--test` option runs all test comparisons and then loads the file with Template Haskell.
### Coding a new derivation
My best suggestion, start with a similar instance, i.e. to make `Eq2` from `Eq` do:
* Copy `Data/Derive/Eq.hs` to `Data/Derive/Eq2.hs`
* Rename some of the bits in `Eq2.hs` from `Eq`
* `ghci` -- load derive
* `:main` --generate -- this adds Eq2.hs to the .cabal/All.hs files etc
* `:reload` -- reload with Eq2.hs
Now fix up `Eq2.hs` appropriately.
derive-2.6.5/Setup.hs 0000644 0000000 0000000 00000000056 07346545000 012630 0 ustar 00 0000000 0000000 import Distribution.Simple
main = defaultMain
derive-2.6.5/derive.cabal 0000644 0000000 0000000 00000006160 07346545000 013440 0 ustar 00 0000000 0000000 cabal-version: 1.18
build-type: Simple
name: derive
version: 2.6.5
copyright: Neil Mitchell 2006-2017
author: Neil Mitchell and others
maintainer: None
homepage: https://github.com/ndmitchell/derive#readme
bug-reports: https://github.com/ndmitchell/derive/issues
license: BSD3
license-file: LICENSE
synopsis: A program and library to derive instances for data types
category: Development
description:
Data.Derive is a library and a tool for deriving instances for Haskell programs.
It is designed to work with custom derivations, SYB and Template Haskell mechanisms.
The tool requires GHC, but the generated code is portable to all compilers.
We see this tool as a competitor to DrIFT.
extra-doc-files:
README.md
CHANGES.txt
tested-with: GHC==8.2.1, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3
source-repository head
type: git
location: https://github.com/ndmitchell/derive.git
executable derive
default-language: Haskell2010
build-depends: base==4.* , derive
main-is: Main.hs
library
default-language: Haskell2010
hs-source-dirs: src
build-depends:
base == 4.*,
filepath, syb, template-haskell, containers, pretty,
directory, process, bytestring,
haskell-src-exts == 1.20.*,
transformers >= 0.2,
uniplate >= 1.5 && < 1.7
exposed-modules:
Data.DeriveMain
Data.DeriveTH
Data.DeriveDSL
Data.Derive.All
Data.Derive.DSL.Apply
Data.Derive.DSL.Derive
Data.Derive.DSL.DSL
Data.Derive.DSL.HSE
Data.Derive.DSL.SYB
Data.Derive.Instance.Arities
Data.Derive.Class.Arities
Data.Derive.Class.Default
Language.Haskell
Language.Haskell.Convert
Language.Haskell.TH.All
Language.Haskell.TH.Compat
Language.Haskell.TH.Data
Language.Haskell.TH.ExpandSynonym
Language.Haskell.TH.Helper
Language.Haskell.TH.Peephole
-- GENERATED START
Data.Derive.Arbitrary
Data.Derive.ArbitraryOld
Data.Derive.Arities
Data.Derive.Binary
Data.Derive.BinaryDefer
Data.Derive.Bounded
Data.Derive.DataAbstract
Data.Derive.Default
Data.Derive.EnumCyclic
Data.Derive.Fold
Data.Derive.From
Data.Derive.Has
Data.Derive.Is
Data.Derive.JSON
Data.Derive.LazySet
Data.Derive.Lens
Data.Derive.Monoid
Data.Derive.NFData
Data.Derive.Ref
Data.Derive.Serial
Data.Derive.Serialize
Data.Derive.Set
Data.Derive.UniplateDirect
Data.Derive.UniplateTypeable
Data.Derive.Update
-- GENERATED STOP
-- Mainly internal but some still people use them
-- to implement derivations outside
Data.Derive.Internal.Derivation
other-modules:
Data.Derive.Internal.Instance
Data.Derive.Internal.Traversal
Derive.Main
Derive.Derivation
Derive.Flags
Derive.Generate
Derive.Test
Derive.Utils
derive-2.6.5/src/Data/Derive/ 0000755 0000000 0000000 00000000000 07346545000 014051 5 ustar 00 0000000 0000000 derive-2.6.5/src/Data/Derive/All.hs 0000644 0000000 0000000 00000003227 07346545000 015121 0 ustar 00 0000000 0000000 -- | This module provides convenience re-exports of all the standard
-- Data.Derive derivations.
module Data.Derive.All (Derivation, derivations, module D) where
import Data.Derive.Internal.Derivation
-- GENERATED START
import Data.Derive.Arbitrary as D
import Data.Derive.ArbitraryOld as D
import Data.Derive.Arities as D
import Data.Derive.Binary as D
import Data.Derive.BinaryDefer as D
import Data.Derive.Bounded as D
import Data.Derive.DataAbstract as D
import Data.Derive.Default as D
import Data.Derive.EnumCyclic as D
import Data.Derive.Fold as D
import Data.Derive.From as D
import Data.Derive.Has as D
import Data.Derive.Is as D
import Data.Derive.JSON as D
import Data.Derive.LazySet as D
import Data.Derive.Lens as D
import Data.Derive.Monoid as D
import Data.Derive.NFData as D
import Data.Derive.Ref as D
import Data.Derive.Serial as D
import Data.Derive.Serialize as D
import Data.Derive.Set as D
import Data.Derive.UniplateDirect as D
import Data.Derive.UniplateTypeable as D
import Data.Derive.Update as D
derivations :: [Derivation]
derivations = [makeArbitrary,makeArbitraryOld,makeArities,makeBinary,makeBinaryDefer,makeBounded,makeDataAbstract,makeDefault,makeEnumCyclic,makeFold,makeFrom,makeHas,makeIs,makeJSON,makeLazySet,makeLens,makeMonoid,makeNFData,makeRef,makeSerial,makeSerialize,makeSet,makeUniplateDirect,makeUniplateTypeable,makeUpdate]
-- GENERATED STOP
derive-2.6.5/src/Data/Derive/Arbitrary.hs 0000644 0000000 0000000 00000012364 07346545000 016352 0 ustar 00 0000000 0000000 module Data.Derive.Arbitrary(makeArbitrary) where
{-
import "QuickCheck" Test.QuickCheck
example :: Custom
instance Arbitrary (Sample a) where
arbitrary = do
x <- choose (0::Int,length [First{},Second{},Third{}] - 1)
case x of
0 -> do return (First)
1 -> do x1 <- arbitrary
x2 <- arbitrary
return (Second x1 x2)
2 -> do x1 <- arbitrary
return (Third x1)
_ -> error "FATAL ERROR: Arbitrary instance, logic bug"
test :: State
instance (CoArbitrary s, Arbitrary s, Arbitrary a) => Arbitrary (State s a) where
arbitrary = do x1 <- arbitrary
return (StateT x1)
-}
import Data.Derive.DSL.HSE
import Data.List
import Data.Generics.Uniplate.DataOnly
-- GENERATED START
import Data.Derive.DSL.DSL
import Data.Derive.Internal.Derivation
makeArbitrary :: Derivation
makeArbitrary = derivationCustomDSL "Arbitrary" custom $
List [Instance [] "Arbitrary" (App "Just" (List [List [App
"InsDecl" (List [App "()" (List []),App "PatBind" (List [App "()"
(List []),App "PVar" (List [App "()" (List []),App "Ident" (List [
App "()" (List []),String "arbitrary"])]),App "UnGuardedRhs" (List
[App "()" (List []),App "Do" (List [App "()" (List []),List [App
"Generator" (List [App "()" (List []),App "PVar" (List [App "()" (
List []),App "Ident" (List [App "()" (List []),String "x"])]),App
"App" (List [App "()" (List []),App "Var" (List [App "()" (List []
),App "UnQual" (List [App "()" (List []),App "Ident" (List [App
"()" (List []),String "choose"])])]),App "Tuple" (List [App "()" (
List []),App "Boxed" (List []),List [App "ExpTypeSig" (List [App
"()" (List []),App "Lit" (List [App "()" (List []),App "Int" (List
[App "()" (List []),Int 0,ShowInt (Int 0)])]),App "TyCon" (List [
App "()" (List []),App "UnQual" (List [App "()" (List []),App
"Ident" (List [App "()" (List []),String "Int"])])])]),App
"InfixApp" (List [App "()" (List []),App "App" (List [App "()" (
List []),App "Var" (List [App "()" (List []),App "UnQual" (List [
App "()" (List []),App "Ident" (List [App "()" (List []),String
"length"])])]),App "List" (List [App "()" (List []),MapCtor (App
"RecConstr" (List [App "()" (List []),App "UnQual" (List [App "()"
(List []),App "Ident" (List [App "()" (List []),CtorName])]),List
[]]))])]),App "QVarOp" (List [App "()" (List []),App "UnQual" (
List [App "()" (List []),App "Symbol" (List [App "()" (List []),
String "-"])])]),App "Lit" (List [App "()" (List []),App "Int" (
List [App "()" (List []),Int 1,ShowInt (Int 1)])])])]])])]),App
"Qualifier" (List [App "()" (List []),App "Case" (List [App "()" (
List []),App "Var" (List [App "()" (List []),App "UnQual" (List [
App "()" (List []),App "Ident" (List [App "()" (List []),String
"x"])])]),Concat (List [MapCtor (App "Alt" (List [App "()" (List [
]),App "PLit" (List [App "()" (List []),App "Signless" (List [App
"()" (List [])]),App "Int" (List [App "()" (List []),CtorIndex,
ShowInt CtorIndex])]),App "UnGuardedRhs" (List [App "()" (List [])
,App "Do" (List [App "()" (List []),Concat (List [MapField (App
"Generator" (List [App "()" (List []),App "PVar" (List [App "()" (
List []),App "Ident" (List [App "()" (List []),Concat (List [
String "x",ShowInt FieldIndex])])]),App "Var" (List [App "()" (
List []),App "UnQual" (List [App "()" (List []),App "Ident" (List
[App "()" (List []),String "arbitrary"])])])])),List [App
"Qualifier" (List [App "()" (List []),App "App" (List [App "()" (
List []),App "Var" (List [App "()" (List []),App "UnQual" (List [
App "()" (List []),App "Ident" (List [App "()" (List []),String
"return"])])]),App "Paren" (List [App "()" (List []),Application (
Concat (List [List [App "Con" (List [App "()" (List []),App
"UnQual" (List [App "()" (List []),App "Ident" (List [App "()" (
List []),CtorName])])])],MapField (App "Var" (List [App "()" (List
[]),App "UnQual" (List [App "()" (List []),App "Ident" (List [App
"()" (List []),Concat (List [String "x",ShowInt FieldIndex])])])])
)]))])])])]])])]),App "Nothing" (List [])])),List [App "Alt" (List
[App "()" (List []),App "PWildCard" (List [App "()" (List [])]),
App "UnGuardedRhs" (List [App "()" (List []),App "App" (List [App
"()" (List []),App "Var" (List [App "()" (List []),App "UnQual" (
List [App "()" (List []),App "Ident" (List [App "()" (List []),
String "error"])])]),App "Lit" (List [App "()" (List []),App
"String" (List [App "()" (List []),String
"FATAL ERROR: Arbitrary instance, logic bug",String
"FATAL ERROR: Arbitrary instance, logic bug"])])])]),App "Nothing"
(List [])])]])])])]])]),App "Nothing" (List [])])])]]))]
-- GENERATED STOP
custom = customContext context
-- Fix the context
-- C a b => Arbitrary a, Arbitrary b
-- a -> b => CoArbitrary a, Arbitrary b
context :: FullDataDecl -> Context () -> Context ()
context (_,d) _ = CxTuple () $ nub $ concatMap (f True . snd) $ concatMap ctorDeclFields $ dataDeclCtors d
where
f b (TyVar _ x) = [ClassA () (qname $ b ? "Arbitrary" $ "CoArbitrary") [TyVar () x]]
f b (TyFun _ x y) = f (not b) x ++ f b y
f b x = concatMap (f b) (children x)
derive-2.6.5/src/Data/Derive/ArbitraryOld.hs 0000644 0000000 0000000 00000011165 07346545000 017007 0 ustar 00 0000000 0000000 module Data.Derive.ArbitraryOld where
{-
import "QuickCheck-1.2.0.0" Test.QuickCheck(Arbitrary(..), choose,variant)
example :: Sample
instance Arbitrary a => Arbitrary (Sample a) where
arbitrary = do
x <- choose (0,length [First{},Second{},Third{}]-1)
case x of
0 -> do return (First)
1 -> do x1 <- arbitrary
x2 <- arbitrary
return (Second x1 x2)
2 -> do x1 <- arbitrary
return (Third x1)
coarbitrary (First) = ()
coarbitrary (Second x1 x2) = ()
coarbitrary (Third x1) = ()
-}
-- GENERATED START
import Data.Derive.DSL.DSL
import Data.Derive.Internal.Derivation
makeArbitraryOld :: Derivation
makeArbitraryOld = derivationDSL "ArbitraryOld" dslArbitraryOld
dslArbitraryOld =
List [Instance ["Arbitrary"] "Arbitrary" (App "Just" (List [List [
App "InsDecl" (List [App "()" (List []),App "PatBind" (List [App
"()" (List []),App "PVar" (List [App "()" (List []),App "Ident" (
List [App "()" (List []),String "arbitrary"])]),App "UnGuardedRhs"
(List [App "()" (List []),App "Do" (List [App "()" (List []),List
[App "Generator" (List [App "()" (List []),App "PVar" (List [App
"()" (List []),App "Ident" (List [App "()" (List []),String "x"])]
),App "App" (List [App "()" (List []),App "Var" (List [App "()" (
List []),App "UnQual" (List [App "()" (List []),App "Ident" (List
[App "()" (List []),String "choose"])])]),App "Tuple" (List [App
"()" (List []),App "Boxed" (List []),List [App "Lit" (List [App
"()" (List []),App "Int" (List [App "()" (List []),Int 0,ShowInt (
Int 0)])]),App "InfixApp" (List [App "()" (List []),App "App" (
List [App "()" (List []),App "Var" (List [App "()" (List []),App
"UnQual" (List [App "()" (List []),App "Ident" (List [App "()" (
List []),String "length"])])]),App "List" (List [App "()" (List []
),MapCtor (App "RecConstr" (List [App "()" (List []),App "UnQual"
(List [App "()" (List []),App "Ident" (List [App "()" (List []),
CtorName])]),List []]))])]),App "QVarOp" (List [App "()" (List [])
,App "UnQual" (List [App "()" (List []),App "Symbol" (List [App
"()" (List []),String "-"])])]),App "Lit" (List [App "()" (List []
),App "Int" (List [App "()" (List []),Int 1,ShowInt (Int 1)])])])]
])])]),App "Qualifier" (List [App "()" (List []),App "Case" (List
[App "()" (List []),App "Var" (List [App "()" (List []),App
"UnQual" (List [App "()" (List []),App "Ident" (List [App "()" (
List []),String "x"])])]),MapCtor (App "Alt" (List [App "()" (List
[]),App "PLit" (List [App "()" (List []),App "Signless" (List [App
"()" (List [])]),App "Int" (List [App "()" (List []),CtorIndex,
ShowInt CtorIndex])]),App "UnGuardedRhs" (List [App "()" (List [])
,App "Do" (List [App "()" (List []),Concat (List [MapField (App
"Generator" (List [App "()" (List []),App "PVar" (List [App "()" (
List []),App "Ident" (List [App "()" (List []),Concat (List [
String "x",ShowInt FieldIndex])])]),App "Var" (List [App "()" (
List []),App "UnQual" (List [App "()" (List []),App "Ident" (List
[App "()" (List []),String "arbitrary"])])])])),List [App
"Qualifier" (List [App "()" (List []),App "App" (List [App "()" (
List []),App "Var" (List [App "()" (List []),App "UnQual" (List [
App "()" (List []),App "Ident" (List [App "()" (List []),String
"return"])])]),App "Paren" (List [App "()" (List []),Application (
Concat (List [List [App "Con" (List [App "()" (List []),App
"UnQual" (List [App "()" (List []),App "Ident" (List [App "()" (
List []),CtorName])])])],MapField (App "Var" (List [App "()" (List
[]),App "UnQual" (List [App "()" (List []),App "Ident" (List [App
"()" (List []),Concat (List [String "x",ShowInt FieldIndex])])])])
)]))])])])]])])]),App "Nothing" (List [])]))])])]])]),App
"Nothing" (List [])])]),App "InsDecl" (List [App "()" (List []),
App "FunBind" (List [App "()" (List []),MapCtor (App "Match" (List
[App "()" (List []),App "Ident" (List [App "()" (List []),String
"coarbitrary"]),List [App "PParen" (List [App "()" (List []),App
"PApp" (List [App "()" (List []),App "UnQual" (List [App "()" (
List []),App "Ident" (List [App "()" (List []),CtorName])]),
MapField (App "PVar" (List [App "()" (List []),App "Ident" (List [
App "()" (List []),Concat (List [String "x",ShowInt FieldIndex])])
]))])])],App "UnGuardedRhs" (List [App "()" (List []),App "Con" (
List [App "()" (List []),App "Special" (List [App "()" (List []),
App "UnitCon" (List [App "()" (List [])])])])]),App "Nothing" (
List [])]))])])]]))]
-- GENERATED STOP
derive-2.6.5/src/Data/Derive/Arities.hs 0000644 0000000 0000000 00000002702 07346545000 016006 0 ustar 00 0000000 0000000 module Data.Derive.Arities where
{-
import "derive" Data.Derive.Class.Arities
example :: Sample
instance Arities (Sample a) where
arities _ = [const 0 First{}, const 2 Second{}, const 1 Third{}]
test :: []
instance Arities [a] where
arities _ = [0,2]
test :: Bool
instance Arities Bool where
arities _ = [0,0]
test :: Either
instance Arities (Either a b) where
arities _ = [1,1]
-}
-- GENERATED START
import Data.Derive.DSL.DSL
import Data.Derive.Internal.Derivation
makeArities :: Derivation
makeArities = derivationDSL "Arities" dslArities
dslArities =
List [Instance [] "Arities" (App "Just" (List [List [App "InsDecl"
(List [App "()" (List []),App "FunBind" (List [App "()" (List []),
List [App "Match" (List [App "()" (List []),App "Ident" (List [App
"()" (List []),String "arities"]),List [App "PWildCard" (List [App
"()" (List [])])],App "UnGuardedRhs" (List [App "()" (List []),App
"List" (List [App "()" (List []),MapCtor (Application (List [App
"Var" (List [App "()" (List []),App "UnQual" (List [App "()" (List
[]),App "Ident" (List [App "()" (List []),String "const"])])]),App
"Lit" (List [App "()" (List []),App "Int" (List [App "()" (List []
),CtorArity,ShowInt CtorArity])]),App "RecConstr" (List [App "()"
(List []),App "UnQual" (List [App "()" (List []),App "Ident" (List
[App "()" (List []),CtorName])]),List []])]))])]),App "Nothing" (
List [])])]])])]]))]
-- GENERATED STOP
derive-2.6.5/src/Data/Derive/Binary.hs 0000644 0000000 0000000 00000023350 07346545000 015634 0 ustar 00 0000000 0000000 module Data.Derive.Binary where
{-
import "binary" Data.Binary
example :: Sample
instance Binary alpha => Binary (Sample alpha) where
put x = case x of
First -> do putTag 0
Second x1 x2 -> do putTag 1 ; put x1 ; put x2
Third x1 -> do putTag 2 ; put x1
where
useTag = length [First{}, Second{}, Third{}] > 1
putTag x = when useTag (putWord8 x)
get = do
i <- getTag
case i of
0 -> do return (First)
1 -> do x1 <- get ; x2 <- get ; return (Second x1 x2)
2 -> do x1 <- get ; return (Third x1)
_ -> error "Corrupted binary data for Sample"
where
useTag = length [First{}, Second{}, Third{}] > 1
getTag = if useTag then getWord8 else return 0
test :: List
instance Binary a => Binary (List a) where
put x = case x of
Nil -> putWord8 0
Cons x1 x2 -> do putWord8 1; put x1; put x2
get = do
i <- getWord8
case i of
0 -> return Nil
1 -> do x1 <- get; x2 <- get; return (Cons x1 x2)
_ -> error "Corrupted binary data for List"
test :: Assoced
instance Binary typ => Binary (Assoced typ) where
put (Assoced x1 x2) = do put x1; put x2
get = do x1 <- get; x2 <- get; return (Assoced x1 x2)
-}
-- GENERATED START
import Data.Derive.DSL.DSL
import Data.Derive.Internal.Derivation
makeBinary :: Derivation
makeBinary = derivationDSL "Binary" dslBinary
dslBinary =
List [Instance ["Binary"] "Binary" (App "Just" (List [List [App
"InsDecl" (List [App "()" (List []),App "FunBind" (List [App "()"
(List []),List [App "Match" (List [App "()" (List []),App "Ident"
(List [App "()" (List []),String "put"]),List [App "PVar" (List [
App "()" (List []),App "Ident" (List [App "()" (List []),String
"x"])])],App "UnGuardedRhs" (List [App "()" (List []),App "Case" (
List [App "()" (List []),App "Var" (List [App "()" (List []),App
"UnQual" (List [App "()" (List []),App "Ident" (List [App "()" (
List []),String "x"])])]),MapCtor (App "Alt" (List [App "()" (List
[]),App "PApp" (List [App "()" (List []),App "UnQual" (List [App
"()" (List []),App "Ident" (List [App "()" (List []),CtorName])]),
MapField (App "PVar" (List [App "()" (List []),App "Ident" (List [
App "()" (List []),Concat (List [String "x",ShowInt FieldIndex])])
]))]),App "UnGuardedRhs" (List [App "()" (List []),App "Do" (List
[App "()" (List []),Concat (List [List [App "Qualifier" (List [App
"()" (List []),App "App" (List [App "()" (List []),App "Var" (List
[App "()" (List []),App "UnQual" (List [App "()" (List []),App
"Ident" (List [App "()" (List []),String "putTag"])])]),App "Lit"
(List [App "()" (List []),App "Int" (List [App "()" (List []),
CtorIndex,ShowInt CtorIndex])])])])],MapField (App "Qualifier" (
List [App "()" (List []),App "App" (List [App "()" (List []),App
"Var" (List [App "()" (List []),App "UnQual" (List [App "()" (List
[]),App "Ident" (List [App "()" (List []),String "put"])])]),App
"Var" (List [App "()" (List []),App "UnQual" (List [App "()" (List
[]),App "Ident" (List [App "()" (List []),Concat (List [String "x"
,ShowInt FieldIndex])])])])])]))])])]),App "Nothing" (List [])]))]
)]),App "Just" (List [App "BDecls" (List [App "()" (List []),List
[App "PatBind" (List [App "()" (List []),App "PVar" (List [App
"()" (List []),App "Ident" (List [App "()" (List []),String
"useTag"])]),App "UnGuardedRhs" (List [App "()" (List []),App
"InfixApp" (List [App "()" (List []),App "App" (List [App "()" (
List []),App "Var" (List [App "()" (List []),App "UnQual" (List [
App "()" (List []),App "Ident" (List [App "()" (List []),String
"length"])])]),App "List" (List [App "()" (List []),MapCtor (App
"RecConstr" (List [App "()" (List []),App "UnQual" (List [App "()"
(List []),App "Ident" (List [App "()" (List []),CtorName])]),List
[]]))])]),App "QVarOp" (List [App "()" (List []),App "UnQual" (
List [App "()" (List []),App "Symbol" (List [App "()" (List []),
String ">"])])]),App "Lit" (List [App "()" (List []),App "Int" (
List [App "()" (List []),Int 1,ShowInt (Int 1)])])])]),App
"Nothing" (List [])]),App "FunBind" (List [App "()" (List []),List
[App "Match" (List [App "()" (List []),App "Ident" (List [App "()"
(List []),String "putTag"]),List [App "PVar" (List [App "()" (List
[]),App "Ident" (List [App "()" (List []),String "x"])])],App
"UnGuardedRhs" (List [App "()" (List []),Application (List [App
"Var" (List [App "()" (List []),App "UnQual" (List [App "()" (List
[]),App "Ident" (List [App "()" (List []),String "when"])])]),App
"Var" (List [App "()" (List []),App "UnQual" (List [App "()" (List
[]),App "Ident" (List [App "()" (List []),String "useTag"])])]),
App "Paren" (List [App "()" (List []),App "App" (List [App "()" (
List []),App "Var" (List [App "()" (List []),App "UnQual" (List [
App "()" (List []),App "Ident" (List [App "()" (List []),Concat (
List [String "putWord",ShowInt (Int 8)])])])]),App "Var" (List [
App "()" (List []),App "UnQual" (List [App "()" (List []),App
"Ident" (List [App "()" (List []),String "x"])])])])])])]),App
"Nothing" (List [])])]])]])])])]])]),App "InsDecl" (List [App "()"
(List []),App "PatBind" (List [App "()" (List []),App "PVar" (List
[App "()" (List []),App "Ident" (List [App "()" (List []),String
"get"])]),App "UnGuardedRhs" (List [App "()" (List []),App "Do" (
List [App "()" (List []),List [App "Generator" (List [App "()" (
List []),App "PVar" (List [App "()" (List []),App "Ident" (List [
App "()" (List []),String "i"])]),App "Var" (List [App "()" (List
[]),App "UnQual" (List [App "()" (List []),App "Ident" (List [App
"()" (List []),String "getTag"])])])]),App "Qualifier" (List [App
"()" (List []),App "Case" (List [App "()" (List []),App "Var" (
List [App "()" (List []),App "UnQual" (List [App "()" (List []),
App "Ident" (List [App "()" (List []),String "i"])])]),Concat (
List [MapCtor (App "Alt" (List [App "()" (List []),App "PLit" (
List [App "()" (List []),App "Signless" (List [App "()" (List [])]
),App "Int" (List [App "()" (List []),CtorIndex,ShowInt CtorIndex]
)]),App "UnGuardedRhs" (List [App "()" (List []),App "Do" (List [
App "()" (List []),Concat (List [MapField (App "Generator" (List [
App "()" (List []),App "PVar" (List [App "()" (List []),App
"Ident" (List [App "()" (List []),Concat (List [String "x",ShowInt
FieldIndex])])]),App "Var" (List [App "()" (List []),App "UnQual"
(List [App "()" (List []),App "Ident" (List [App "()" (List []),
String "get"])])])])),List [App "Qualifier" (List [App "()" (List
[]),App "App" (List [App "()" (List []),App "Var" (List [App "()"
(List []),App "UnQual" (List [App "()" (List []),App "Ident" (List
[App "()" (List []),String "return"])])]),App "Paren" (List [App
"()" (List []),Application (Concat (List [List [App "Con" (List [
App "()" (List []),App "UnQual" (List [App "()" (List []),App
"Ident" (List [App "()" (List []),CtorName])])])],MapField (App
"Var" (List [App "()" (List []),App "UnQual" (List [App "()" (List
[]),App "Ident" (List [App "()" (List []),Concat (List [String "x"
,ShowInt FieldIndex])])])]))]))])])])]])])]),App "Nothing" (List [
])])),List [App "Alt" (List [App "()" (List []),App "PWildCard" (
List [App "()" (List [])]),App "UnGuardedRhs" (List [App "()" (
List []),App "App" (List [App "()" (List []),App "Var" (List [App
"()" (List []),App "UnQual" (List [App "()" (List []),App "Ident"
(List [App "()" (List []),String "error"])])]),App "Lit" (List [
App "()" (List []),App "String" (List [App "()" (List []),Concat (
List [String "Corrupted binary data for ",DataName]),Concat (List
[String "Corrupted binary data for ",DataName])])])])]),App
"Nothing" (List [])])]])])])]])]),App "Just" (List [App "BDecls" (
List [App "()" (List []),List [App "PatBind" (List [App "()" (List
[]),App "PVar" (List [App "()" (List []),App "Ident" (List [App
"()" (List []),String "useTag"])]),App "UnGuardedRhs" (List [App
"()" (List []),App "InfixApp" (List [App "()" (List []),App "App"
(List [App "()" (List []),App "Var" (List [App "()" (List []),App
"UnQual" (List [App "()" (List []),App "Ident" (List [App "()" (
List []),String "length"])])]),App "List" (List [App "()" (List []
),MapCtor (App "RecConstr" (List [App "()" (List []),App "UnQual"
(List [App "()" (List []),App "Ident" (List [App "()" (List []),
CtorName])]),List []]))])]),App "QVarOp" (List [App "()" (List [])
,App "UnQual" (List [App "()" (List []),App "Symbol" (List [App
"()" (List []),String ">"])])]),App "Lit" (List [App "()" (List []
),App "Int" (List [App "()" (List []),Int 1,ShowInt (Int 1)])])])]
),App "Nothing" (List [])]),App "PatBind" (List [App "()" (List []
),App "PVar" (List [App "()" (List []),App "Ident" (List [App "()"
(List []),String "getTag"])]),App "UnGuardedRhs" (List [App "()" (
List []),App "If" (List [App "()" (List []),App "Var" (List [App
"()" (List []),App "UnQual" (List [App "()" (List []),App "Ident"
(List [App "()" (List []),String "useTag"])])]),App "Var" (List [
App "()" (List []),App "UnQual" (List [App "()" (List []),App
"Ident" (List [App "()" (List []),Concat (List [String "getWord",
ShowInt (Int 8)])])])]),App "App" (List [App "()" (List []),App
"Var" (List [App "()" (List []),App "UnQual" (List [App "()" (List
[]),App "Ident" (List [App "()" (List []),String "return"])])]),
App "Lit" (List [App "()" (List []),App "Int" (List [App "()" (
List []),Int 0,ShowInt (Int 0)])])])])]),App "Nothing" (List [])])
]])])])])]]))]
-- GENERATED STOP
derive-2.6.5/src/Data/Derive/BinaryDefer.hs 0000644 0000000 0000000 00000011002 07346545000 016571 0 ustar 00 0000000 0000000 module Data.Derive.BinaryDefer where
{-
import "binarydefer" Data.Binary.Defer
example :: Sample
instance BinaryDefer a => BinaryDefer (Sample a) where
bothDefer = defer [\ ~(o@(First)) -> if null [] then unit (First) < if null [const () x1, const () x2] then unit (Second x1 x2) < if null [const () x1] then unit (Third x1) < BinaryDefer (FailList e a) where
bothDefer = defer [\ ~(o@Zoro) -> unit Zoro < unit Fial << x1
,\ ~(Const x1 x2) -> unit Const << x1 << x2
]
-}
-- GENERATED START
import Data.Derive.DSL.DSL
import Data.Derive.Internal.Derivation
makeBinaryDefer :: Derivation
makeBinaryDefer = derivationDSL "BinaryDefer" dslBinaryDefer
dslBinaryDefer =
List [Instance ["BinaryDefer"] "BinaryDefer" (App "Just" (List [
List [App "InsDecl" (List [App "()" (List []),App "PatBind" (List
[App "()" (List []),App "PVar" (List [App "()" (List []),App
"Ident" (List [App "()" (List []),String "bothDefer"])]),App
"UnGuardedRhs" (List [App "()" (List []),App "App" (List [App "()"
(List []),App "Var" (List [App "()" (List []),App "UnQual" (List [
App "()" (List []),App "Ident" (List [App "()" (List []),String
"defer"])])]),App "List" (List [App "()" (List []),MapCtor (App
"Lambda" (List [App "()" (List []),List [App "PIrrPat" (List [App
"()" (List []),App "PParen" (List [App "()" (List []),App "PAsPat"
(List [App "()" (List []),App "Ident" (List [App "()" (List []),
String "o"]),App "PParen" (List [App "()" (List []),App "PApp" (
List [App "()" (List []),App "UnQual" (List [App "()" (List []),
App "Ident" (List [App "()" (List []),CtorName])]),MapField (App
"PVar" (List [App "()" (List []),App "Ident" (List [App "()" (List
[]),Concat (List [String "x",ShowInt FieldIndex])])]))])])])])])],
App "If" (List [App "()" (List []),App "App" (List [App "()" (List
[]),App "Var" (List [App "()" (List []),App "UnQual" (List [App
"()" (List []),App "Ident" (List [App "()" (List []),String "null"
])])]),App "List" (List [App "()" (List []),MapField (Application
(List [App "Var" (List [App "()" (List []),App "UnQual" (List [App
"()" (List []),App "Ident" (List [App "()" (List []),String
"const"])])]),App "Con" (List [App "()" (List []),App "Special" (
List [App "()" (List []),App "UnitCon" (List [App "()" (List [])])
])]),App "Var" (List [App "()" (List []),App "UnQual" (List [App
"()" (List []),App "Ident" (List [App "()" (List []),Concat (List
[String "x",ShowInt FieldIndex])])])])]))])]),App "InfixApp" (List
[App "()" (List []),App "App" (List [App "()" (List []),App "Var"
(List [App "()" (List []),App "UnQual" (List [App "()" (List []),
App "Ident" (List [App "()" (List []),String "unit"])])]),App
"Paren" (List [App "()" (List []),Application (Concat (List [List
[App "Con" (List [App "()" (List []),App "UnQual" (List [App "()"
(List []),App "Ident" (List [App "()" (List []),CtorName])])])],
MapField (App "Var" (List [App "()" (List []),App "UnQual" (List [
App "()" (List []),App "Ident" (List [App "()" (List []),Concat (
List [String "x",ShowInt FieldIndex])])])]))]))])]),App "QVarOp" (
List [App "()" (List []),App "UnQual" (List [App "()" (List []),
App "Symbol" (List [App "()" (List []),String "<