{-# LANGUAGE CPP #-}
-- |
-- Module      : Test.LeanCheck.Basic
-- Copyright   : (c) 2015-2020 Rudy Matela
-- License     : 3-Clause BSD  (see the file LICENSE)
-- Maintainer  : Rudy Matela <rudy@matela.com.br>
--
-- This module is part of LeanCheck,
-- a simple enumerative property-based testing library.
--
-- This module exports "Test.LeanCheck.Core" along with:
--
--   * support for 'Listable' 6-tuples up to 12-tuples;
--   * 'tiers' constructors (@consN@) with arities from 6 up to 12;
--   * a 'Listable' 'Word' instance;
--   * a 'Listable' 'Ratio' instance (consequently 'Listable' 'Rational');
--   * a 'Listable' 'Complex' instance;
--   * 'Listable' 'Int8/16/32/64' instances;
--   * 'Listable' 'Word8/16/32/64' instances;
--   * 'Listable' instances for "Foreign.C" types;
--   * a 'Listable' 'ExitCode' instance;
--   * a 'Listable' 'GeneralCategory' instance;
--   * 'Listable' 'Buffer/IO/SeekMode' instances;
--   * the operators 'addWeight' and 'ofWeight'.
--
-- The above includes all types defined in the Haskell 2010 Report
-- with the exception of Array, IO, Handle, HandlePosn, IOErrorType.
--
-- "Test.LeanCheck" already exports everything from this module.
-- You are probably better off importing it.
--
-- You should /only/ import "Test.LeanCheck.Basic"
-- if you /only/ want the above basic functionality.
module Test.LeanCheck.Basic
  ( module Test.LeanCheck.Core

  , cons6
  , cons7
  , cons8
  , cons9
  , cons10
  , cons11
  , cons12

  , ofWeight
  , addWeight
  )
where

import Test.LeanCheck.Core
import Data.Ratio
import Data.Complex
import Data.Int
import Data.Word
import Data.Char (GeneralCategory)
import System.IO (IOMode (..), BufferMode (..), SeekMode (..))
import Foreign.C
import System.Exit

instance (Listable a, Listable b, Listable c,
          Listable d, Listable e, Listable f) =>
         Listable (a,b,c,d,e,f) where
  tiers :: [[(a, b, c, d, e, f)]]
tiers  =  (a -> (b, c, d, e, f) -> (a, b, c, d, e, f))
-> [[a]] -> [[(b, c, d, e, f)]] -> [[(a, b, c, d, e, f)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (\a
x (b
y,c
z,d
w,e
v,f
u) -> (a
x,b
y,c
z,d
w,e
v,f
u)) [[a]]
forall a. Listable a => [[a]]
tiers [[(b, c, d, e, f)]]
forall a. Listable a => [[a]]
tiers

instance (Listable a, Listable b, Listable c, Listable d,
          Listable e, Listable f, Listable g) =>
         Listable (a,b,c,d,e,f,g) where
  tiers :: [[(a, b, c, d, e, f, g)]]
tiers  =  (a -> (b, c, d, e, f, g) -> (a, b, c, d, e, f, g))
-> [[a]] -> [[(b, c, d, e, f, g)]] -> [[(a, b, c, d, e, f, g)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (\a
x (b
y,c
z,d
w,e
v,f
u,g
r) -> (a
x,b
y,c
z,d
w,e
v,f
u,g
r)) [[a]]
forall a. Listable a => [[a]]
tiers [[(b, c, d, e, f, g)]]
forall a. Listable a => [[a]]
tiers

instance (Listable a, Listable b, Listable c, Listable d,
          Listable e, Listable f, Listable g, Listable h) =>
         Listable (a,b,c,d,e,f,g,h) where
  tiers :: [[(a, b, c, d, e, f, g, h)]]
tiers  =  (a -> (b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h))
-> [[a]]
-> [[(b, c, d, e, f, g, h)]]
-> [[(a, b, c, d, e, f, g, h)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (\a
x (b
y,c
z,d
w,e
v,f
u,g
r,h
s) -> (a
x,b
y,c
z,d
w,e
v,f
u,g
r,h
s)) [[a]]
forall a. Listable a => [[a]]
tiers [[(b, c, d, e, f, g, h)]]
forall a. Listable a => [[a]]
tiers

instance (Listable a, Listable b, Listable c, Listable d, Listable e,
          Listable f, Listable g, Listable h, Listable i) =>
         Listable (a,b,c,d,e,f,g,h,i) where
  tiers :: [[(a, b, c, d, e, f, g, h, i)]]
tiers  =  (a -> (b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i))
-> [[a]]
-> [[(b, c, d, e, f, g, h, i)]]
-> [[(a, b, c, d, e, f, g, h, i)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (\a
x (b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t) -> (a
x,b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t))
                        [[a]]
forall a. Listable a => [[a]]
tiers [[(b, c, d, e, f, g, h, i)]]
forall a. Listable a => [[a]]
tiers

instance (Listable a, Listable b, Listable c, Listable d, Listable e,
          Listable f, Listable g, Listable h, Listable i, Listable j) =>
         Listable (a,b,c,d,e,f,g,h,i,j) where
  tiers :: [[(a, b, c, d, e, f, g, h, i, j)]]
tiers  =  (a
 -> (b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j))
-> [[a]]
-> [[(b, c, d, e, f, g, h, i, j)]]
-> [[(a, b, c, d, e, f, g, h, i, j)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (\a
x (b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t,j
o) -> (a
x,b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t,j
o))
                        [[a]]
forall a. Listable a => [[a]]
tiers [[(b, c, d, e, f, g, h, i, j)]]
forall a. Listable a => [[a]]
tiers

instance (Listable a, Listable b, Listable c, Listable d,
          Listable e, Listable f, Listable g, Listable h,
          Listable i, Listable j, Listable k) =>
         Listable (a,b,c,d,e,f,g,h,i,j,k) where
  tiers :: [[(a, b, c, d, e, f, g, h, i, j, k)]]
tiers  =  (a
 -> (b, c, d, e, f, g, h, i, j, k)
 -> (a, b, c, d, e, f, g, h, i, j, k))
-> [[a]]
-> [[(b, c, d, e, f, g, h, i, j, k)]]
-> [[(a, b, c, d, e, f, g, h, i, j, k)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (\a
x (b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t,j
o,k
p) -> (a
x,b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t,j
o,k
p))
                        [[a]]
forall a. Listable a => [[a]]
tiers [[(b, c, d, e, f, g, h, i, j, k)]]
forall a. Listable a => [[a]]
tiers

instance (Listable a, Listable b, Listable c, Listable d,
          Listable e, Listable f, Listable g, Listable h,
          Listable i, Listable j, Listable k, Listable l) =>
         Listable (a,b,c,d,e,f,g,h,i,j,k,l) where
  tiers :: [[(a, b, c, d, e, f, g, h, i, j, k, l)]]
tiers  =  (a
 -> (b, c, d, e, f, g, h, i, j, k, l)
 -> (a, b, c, d, e, f, g, h, i, j, k, l))
-> [[a]]
-> [[(b, c, d, e, f, g, h, i, j, k, l)]]
-> [[(a, b, c, d, e, f, g, h, i, j, k, l)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (\a
x (b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t,j
o,k
p,l
q) ->
                          (a
x,b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t,j
o,k
p,l
q))
                        [[a]]
forall a. Listable a => [[a]]
tiers [[(b, c, d, e, f, g, h, i, j, k, l)]]
forall a. Listable a => [[a]]
tiers

-- | Returns tiers of applications of a 6-argument constructor.
cons6 :: (Listable a, Listable b, Listable c, Listable d, Listable e, Listable f)
      => (a -> b -> c -> d -> e -> f -> g) -> [[g]]
cons6 :: (a -> b -> c -> d -> e -> f -> g) -> [[g]]
cons6 a -> b -> c -> d -> e -> f -> g
f  =  [[g]] -> [[g]]
forall a. [[a]] -> [[a]]
delay ([[g]] -> [[g]]) -> [[g]] -> [[g]]
forall a b. (a -> b) -> a -> b
$ ((a, b, c, d, e, f) -> g) -> [[(a, b, c, d, e, f)]] -> [[g]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c -> d -> e -> f -> g) -> (a, b, c, d, e, f) -> g
forall a b c d e f g.
(a -> b -> c -> d -> e -> f -> g) -> (a, b, c, d, e, f) -> g
uncurry6 a -> b -> c -> d -> e -> f -> g
f) [[(a, b, c, d, e, f)]]
forall a. Listable a => [[a]]
tiers

-- | Returns tiers of applications of a 7-argument constructor.
cons7 :: (Listable a, Listable b, Listable c, Listable d,
          Listable e, Listable f, Listable g)
      => (a -> b -> c -> d -> e -> f -> g -> h) -> [[h]]
cons7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [[h]]
cons7 a -> b -> c -> d -> e -> f -> g -> h
f  =  [[h]] -> [[h]]
forall a. [[a]] -> [[a]]
delay ([[h]] -> [[h]]) -> [[h]] -> [[h]]
forall a b. (a -> b) -> a -> b
$ ((a, b, c, d, e, f, g) -> h) -> [[(a, b, c, d, e, f, g)]] -> [[h]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c -> d -> e -> f -> g -> h)
-> (a, b, c, d, e, f, g) -> h
forall a b c d e f g h.
(a -> b -> c -> d -> e -> f -> g -> h)
-> (a, b, c, d, e, f, g) -> h
uncurry7 a -> b -> c -> d -> e -> f -> g -> h
f) [[(a, b, c, d, e, f, g)]]
forall a. Listable a => [[a]]
tiers

-- | Returns tiers of applications of a 8-argument constructor.
cons8 :: (Listable a, Listable b, Listable c, Listable d,
          Listable e, Listable f, Listable g, Listable h)
      => (a -> b -> c -> d -> e -> f -> g -> h -> i) -> [[i]]
cons8 :: (a -> b -> c -> d -> e -> f -> g -> h -> i) -> [[i]]
cons8 a -> b -> c -> d -> e -> f -> g -> h -> i
f  =  [[i]] -> [[i]]
forall a. [[a]] -> [[a]]
delay ([[i]] -> [[i]]) -> [[i]] -> [[i]]
forall a b. (a -> b) -> a -> b
$ ((a, b, c, d, e, f, g, h) -> i)
-> [[(a, b, c, d, e, f, g, h)]] -> [[i]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c -> d -> e -> f -> g -> h -> i)
-> (a, b, c, d, e, f, g, h) -> i
forall a b c d e f g h i.
(a -> b -> c -> d -> e -> f -> g -> h -> i)
-> (a, b, c, d, e, f, g, h) -> i
uncurry8 a -> b -> c -> d -> e -> f -> g -> h -> i
f) [[(a, b, c, d, e, f, g, h)]]
forall a. Listable a => [[a]]
tiers

-- | Returns tiers of applications of a 9-argument constructor.
cons9 :: (Listable a, Listable b, Listable c, Listable d, Listable e,
          Listable f, Listable g, Listable h, Listable i)
      => (a -> b -> c -> d -> e -> f -> g -> h -> i -> j) -> [[j]]
cons9 :: (a -> b -> c -> d -> e -> f -> g -> h -> i -> j) -> [[j]]
cons9 a -> b -> c -> d -> e -> f -> g -> h -> i -> j
f  =  [[j]] -> [[j]]
forall a. [[a]] -> [[a]]
delay ([[j]] -> [[j]]) -> [[j]] -> [[j]]
forall a b. (a -> b) -> a -> b
$ ((a, b, c, d, e, f, g, h, i) -> j)
-> [[(a, b, c, d, e, f, g, h, i)]] -> [[j]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c -> d -> e -> f -> g -> h -> i -> j)
-> (a, b, c, d, e, f, g, h, i) -> j
forall a b c d e f g h i j.
(a -> b -> c -> d -> e -> f -> g -> h -> i -> j)
-> (a, b, c, d, e, f, g, h, i) -> j
uncurry9 a -> b -> c -> d -> e -> f -> g -> h -> i -> j
f) [[(a, b, c, d, e, f, g, h, i)]]
forall a. Listable a => [[a]]
tiers

-- | Returns tiers of applications of a 10-argument constructor.
cons10 :: (Listable a, Listable b, Listable c, Listable d, Listable e,
           Listable f, Listable g, Listable h, Listable i, Listable j)
       => (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k) -> [[k]]
cons10 :: (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k) -> [[k]]
cons10 a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k
f  =  [[k]] -> [[k]]
forall a. [[a]] -> [[a]]
delay ([[k]] -> [[k]]) -> [[k]] -> [[k]]
forall a b. (a -> b) -> a -> b
$ ((a, b, c, d, e, f, g, h, i, j) -> k)
-> [[(a, b, c, d, e, f, g, h, i, j)]] -> [[k]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k)
-> (a, b, c, d, e, f, g, h, i, j) -> k
forall a b c d e f g h i j k.
(a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k)
-> (a, b, c, d, e, f, g, h, i, j) -> k
uncurry10 a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k
f) [[(a, b, c, d, e, f, g, h, i, j)]]
forall a. Listable a => [[a]]
tiers

-- | Returns tiers of applications of a 11-argument constructor.
cons11 :: (Listable a, Listable b, Listable c, Listable d,
           Listable e, Listable f, Listable g, Listable h,
           Listable i, Listable j, Listable k)
       => (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l) -> [[l]]
cons11 :: (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l) -> [[l]]
cons11 a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l
f  =  [[l]] -> [[l]]
forall a. [[a]] -> [[a]]
delay ([[l]] -> [[l]]) -> [[l]] -> [[l]]
forall a b. (a -> b) -> a -> b
$ ((a, b, c, d, e, f, g, h, i, j, k) -> l)
-> [[(a, b, c, d, e, f, g, h, i, j, k)]] -> [[l]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l)
-> (a, b, c, d, e, f, g, h, i, j, k) -> l
forall a b c d e f g h i j k l.
(a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l)
-> (a, b, c, d, e, f, g, h, i, j, k) -> l
uncurry11 a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l
f) [[(a, b, c, d, e, f, g, h, i, j, k)]]
forall a. Listable a => [[a]]
tiers

-- | Returns tiers of applications of a 12-argument constructor.
cons12 :: (Listable a, Listable b, Listable c, Listable d,
           Listable e, Listable f, Listable g, Listable h,
           Listable i, Listable j, Listable k, Listable l)
       => (a->b->c->d->e->f->g->h->i->j->k->l->m) -> [[m]]
cons12 :: (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l -> m)
-> [[m]]
cons12 a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l -> m
f  =  [[m]] -> [[m]]
forall a. [[a]] -> [[a]]
delay ([[m]] -> [[m]]) -> [[m]] -> [[m]]
forall a b. (a -> b) -> a -> b
$ ((a, b, c, d, e, f, g, h, i, j, k, l) -> m)
-> [[(a, b, c, d, e, f, g, h, i, j, k, l)]] -> [[m]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l -> m)
-> (a, b, c, d, e, f, g, h, i, j, k, l) -> m
forall a b c d e f g h i j k l m.
(a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l -> m)
-> (a, b, c, d, e, f, g, h, i, j, k, l) -> m
uncurry12 a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l -> m
f) [[(a, b, c, d, e, f, g, h, i, j, k, l)]]
forall a. Listable a => [[a]]
tiers

uncurry6 :: (a->b->c->d->e->f->g) -> (a,b,c,d,e,f) -> g
uncurry6 :: (a -> b -> c -> d -> e -> f -> g) -> (a, b, c, d, e, f) -> g
uncurry6 a -> b -> c -> d -> e -> f -> g
f (a
x,b
y,c
z,d
w,e
v,f
u)  =  a -> b -> c -> d -> e -> f -> g
f a
x b
y c
z d
w e
v f
u

uncurry7 :: (a->b->c->d->e->f->g->h) -> (a,b,c,d,e,f,g) -> h
uncurry7 :: (a -> b -> c -> d -> e -> f -> g -> h)
-> (a, b, c, d, e, f, g) -> h
uncurry7 a -> b -> c -> d -> e -> f -> g -> h
f (a
x,b
y,c
z,d
w,e
v,f
u,g
r)  =  a -> b -> c -> d -> e -> f -> g -> h
f a
x b
y c
z d
w e
v f
u g
r

uncurry8 :: (a->b->c->d->e->f->g->h->i) -> (a,b,c,d,e,f,g,h) -> i
uncurry8 :: (a -> b -> c -> d -> e -> f -> g -> h -> i)
-> (a, b, c, d, e, f, g, h) -> i
uncurry8 a -> b -> c -> d -> e -> f -> g -> h -> i
f (a
x,b
y,c
z,d
w,e
v,f
u,g
r,h
s)  =  a -> b -> c -> d -> e -> f -> g -> h -> i
f a
x b
y c
z d
w e
v f
u g
r h
s

uncurry9 :: (a->b->c->d->e->f->g->h->i->j) -> (a,b,c,d,e,f,g,h,i) -> j
uncurry9 :: (a -> b -> c -> d -> e -> f -> g -> h -> i -> j)
-> (a, b, c, d, e, f, g, h, i) -> j
uncurry9 a -> b -> c -> d -> e -> f -> g -> h -> i -> j
f (a
x,b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t)  =  a -> b -> c -> d -> e -> f -> g -> h -> i -> j
f a
x b
y c
z d
w e
v f
u g
r h
s i
t

uncurry10 :: (a->b->c->d->e->f->g->h->i->j->k) -> (a,b,c,d,e,f,g,h,i,j) -> k
uncurry10 :: (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k)
-> (a, b, c, d, e, f, g, h, i, j) -> k
uncurry10 a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k
f (a
x,b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t,j
o)  =  a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k
f a
x b
y c
z d
w e
v f
u g
r h
s i
t j
o

uncurry11 :: (a->b->c->d->e->f->g->h->i->j->k->l)
          -> (a,b,c,d,e,f,g,h,i,j,k) -> l
uncurry11 :: (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l)
-> (a, b, c, d, e, f, g, h, i, j, k) -> l
uncurry11 a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l
f (a
x,b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t,j
o,k
p)  =  a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l
f a
x b
y c
z d
w e
v f
u g
r h
s i
t j
o k
p

uncurry12 :: (a->b->c->d->e->f->g->h->i->j->k->l->m)
          -> (a,b,c,d,e,f,g,h,i,j,k,l) -> m
uncurry12 :: (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l -> m)
-> (a, b, c, d, e, f, g, h, i, j, k, l) -> m
uncurry12 a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l -> m
f (a
x,b
y,c
z,d
w,e
v,f
u,g
r,h
s,i
t,j
o,k
p,l
q)  =  a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k -> l -> m
f a
x b
y c
z d
w e
v f
u g
r h
s i
t j
o k
p l
q

-- | > list :: [Rational]  =
--   >   [   0  % 1
--   >   ,   1  % 1
--   >   , (-1) % 1
--   >   ,   1  % 2,   2  % 1
--   >   , (-1) % 2, (-2) % 1
--   >   ,   1  % 3,   3  % 1
--   >   , (-1) % 3, (-3) % 1
--   >   ,   1  % 4,   2  % 3,   3  % 2,   4  % 1
--   >   , (-1) % 4, (-2) % 3, (-3) % 2, (-4) % 1
--   >   ,   1  % 5,   5  % 1
--   >   , (-1) % 5, (-5) % 1
--   >   , ...
--   >   ]
instance (Integral a, Listable a) => Listable (Ratio a) where
  tiers :: [[Ratio a]]
tiers  =  ((a, a) -> Ratio a) -> [[(a, a)]] -> [[Ratio a]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> a -> Ratio a) -> (a, a) -> Ratio a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> Ratio a
forall a. Integral a => a -> a -> Ratio a
(%)) ([[(a, a)]] -> [[Ratio a]])
-> ([[(a, a)]] -> [[(a, a)]]) -> [[(a, a)]] -> [[Ratio a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[(a, a)]] -> [[(a, a)]]
forall a. [[a]] -> [[a]]
reset
        ([[(a, a)]] -> [[Ratio a]]) -> [[(a, a)]] -> [[Ratio a]]
forall a b. (a -> b) -> a -> b
$ [[(a, a)]]
forall a. Listable a => [[a]]
tiers [[(a, a)]] -> ((a, a) -> Bool) -> [[(a, a)]]
forall a. [[a]] -> (a -> Bool) -> [[a]]
`suchThat` (\(a
n,a
d) -> a
d a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
0 Bool -> Bool -> Bool
&& a
n a -> a -> a
forall a. Integral a => a -> a -> a
`gcd` a
d a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
1)

instance (RealFloat a, Listable a) => Listable (Complex a) where
  tiers :: [[Complex a]]
tiers  =  (a -> a -> Complex a) -> [[Complex a]]
forall a b c. (Listable a, Listable b) => (a -> b -> c) -> [[c]]
cons2 a -> a -> Complex a
forall a. a -> a -> Complex a
(:+)

-- | > list :: [Word]  =  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...]
instance Listable Word where
  list :: [Word]
list  =  [Word]
forall a. (Ord a, Num a) => [a]
listIntegral

-- | > list :: [Word8]  =  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ..., 255]
instance Listable Word8 where
  list :: [Word8]
list  =  [Word8]
forall a. (Ord a, Num a) => [a]
listIntegral

-- | > list :: [Word16]  =  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ..., 65535]
instance Listable Word16 where
  list :: [Word16]
list  =  [Word16]
forall a. (Ord a, Num a) => [a]
listIntegral

-- | > list :: [Word32]  =  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...]
instance Listable Word32 where
  list :: [Word32]
list  =  [Word32]
forall a. (Ord a, Num a) => [a]
listIntegral

-- | > list :: [Word64]  =  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...]
instance Listable Word64 where
  list :: [Word64]
list  =  [Word64]
forall a. (Ord a, Num a) => [a]
listIntegral

-- | > list :: [Int8]  =  [0, 1, -1, 2, -2, 3, -3, ..., 127, -127, -128]
instance Listable Int8 where
  list :: [Int8]
list  =  [Int8]
forall a. (Ord a, Num a) => [a]
listIntegral

-- | > list :: [Int16]  =  [0, 1, -1, 2, -2, ..., 32767, -32767, -32768]
instance Listable Int16 where
  list :: [Int16]
list  =  [Int16]
forall a. (Ord a, Num a) => [a]
listIntegral

-- | > list :: [Int32]  =  [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, ...]
instance Listable Int32 where
  list :: [Int32]
list  =  [Int32]
forall a. (Ord a, Num a) => [a]
listIntegral

-- | > list :: [Int64]  =  [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, ...]
instance Listable Int64 where
  list :: [Int64]
list  =  [Int64]
forall a. (Ord a, Num a) => [a]
listIntegral

instance Listable CChar      where  list :: [CChar]
list  =  [CChar]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CSChar     where  list :: [CSChar]
list  =  [CSChar]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CUChar     where  list :: [CUChar]
list  =  [CUChar]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CShort     where  list :: [CShort]
list  =  [CShort]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CUShort    where  list :: [CUShort]
list  =  [CUShort]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CInt       where  list :: [CInt]
list  =  [CInt]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CUInt      where  list :: [CUInt]
list  =  [CUInt]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CLong      where  list :: [CLong]
list  =  [CLong]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CULong     where  list :: [CULong]
list  =  [CULong]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CPtrdiff   where  list :: [CPtrdiff]
list  =  [CPtrdiff]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CSize      where  list :: [CSize]
list  =  [CSize]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CWchar     where  list :: [CWchar]
list  =  [CWchar]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CSigAtomic where  list :: [CSigAtomic]
list  =  [CSigAtomic]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CLLong     where  list :: [CLLong]
list  =  [CLLong]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CULLong    where  list :: [CULLong]
list  =  [CULLong]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CIntPtr    where  list :: [CIntPtr]
list  =  [CIntPtr]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CUIntPtr   where  list :: [CUIntPtr]
list  =  [CUIntPtr]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CIntMax    where  list :: [CIntMax]
list  =  [CIntMax]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CUIntMax   where  list :: [CUIntMax]
list  =  [CUIntMax]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CClock     where  list :: [CClock]
list  =  [CClock]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CTime      where  list :: [CTime]
list  =  [CTime]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CFloat     where  tiers :: [[CFloat]]
tiers  =  [[CFloat]]
forall a. Fractional a => [[a]]
tiersFloating
instance Listable CDouble    where  tiers :: [[CDouble]]
tiers  =  [[CDouble]]
forall a. Fractional a => [[a]]
tiersFloating
#if __GLASGOW_HASKELL__ >= 802
instance Listable CBool      where  list :: [CBool]
list  =  [CBool]
forall a. (Ord a, Num a) => [a]
listIntegral
#endif
#if __GLASGOW_HASKELL__
instance Listable CUSeconds  where  list :: [CUSeconds]
list  =  [CUSeconds]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable CSUSeconds where  list :: [CSUSeconds]
list  =  [CSUSeconds]
forall a. (Ord a, Num a) => [a]
listIntegral
#endif

-- | Only includes valid POSIX exit codes
--
-- > > list :: [ExitCode]
-- > [ExitSuccess, ExitFailure 1, ExitFailure 2, ..., ExitFailure 255]
instance Listable ExitCode where  list :: [ExitCode]
list  =  ExitCode
ExitSuccess ExitCode -> [ExitCode] -> [ExitCode]
forall a. a -> [a] -> [a]
: (Int -> ExitCode) -> [Int] -> [ExitCode]
forall a b. (a -> b) -> [a] -> [b]
map Int -> ExitCode
ExitFailure [Int
1..Int
255]

instance Listable GeneralCategory where  list :: [GeneralCategory]
list  =  [GeneralCategory
forall a. Bounded a => a
minBound..GeneralCategory
forall a. Bounded a => a
maxBound]

instance Listable IOMode where
  tiers :: [[IOMode]]
tiers  =  IOMode -> [[IOMode]]
forall a. a -> [[a]]
cons0 IOMode
ReadMode
         [[IOMode]] -> [[IOMode]] -> [[IOMode]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ IOMode -> [[IOMode]]
forall a. a -> [[a]]
cons0 IOMode
WriteMode
         [[IOMode]] -> [[IOMode]] -> [[IOMode]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ IOMode -> [[IOMode]]
forall a. a -> [[a]]
cons0 IOMode
AppendMode
         [[IOMode]] -> [[IOMode]] -> [[IOMode]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ IOMode -> [[IOMode]]
forall a. a -> [[a]]
cons0 IOMode
ReadWriteMode

instance Listable BufferMode where
  tiers :: [[BufferMode]]
tiers  =  BufferMode -> [[BufferMode]]
forall a. a -> [[a]]
cons0 BufferMode
NoBuffering
         [[BufferMode]] -> [[BufferMode]] -> [[BufferMode]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ BufferMode -> [[BufferMode]]
forall a. a -> [[a]]
cons0 BufferMode
LineBuffering
         [[BufferMode]] -> [[BufferMode]] -> [[BufferMode]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ (Maybe Int -> BufferMode) -> [[BufferMode]]
forall a b. Listable a => (a -> b) -> [[b]]
cons1 Maybe Int -> BufferMode
BlockBuffering

instance Listable SeekMode where
  tiers :: [[SeekMode]]
tiers  =  SeekMode -> [[SeekMode]]
forall a. a -> [[a]]
cons0 SeekMode
AbsoluteSeek
         [[SeekMode]] -> [[SeekMode]] -> [[SeekMode]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ SeekMode -> [[SeekMode]]
forall a. a -> [[a]]
cons0 SeekMode
RelativeSeek
         [[SeekMode]] -> [[SeekMode]] -> [[SeekMode]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ SeekMode -> [[SeekMode]]
forall a. a -> [[a]]
cons0 SeekMode
SeekFromEnd

-- | Resets the weight of a constructor or tiers.
--
-- > > [ [], [], ..., xs, ys, zs, ... ] `ofWeight` 1
-- > [ [], xs, ys, zs, ... ]
--
-- > > [ xs, ys, zs, ... ] `ofWeight` 2
-- > [ [], [], xs, ys, zs, ... ]
--
-- > > [ [], xs, ys, zs, ... ] `ofWeight` 3
-- > [ [], [], [], xs, ys, zs, ... ]
--
-- Typically used as an infix operator when defining 'Listable' instances:
--
-- > instance Listable <Type> where
-- >   tiers  =  ...
-- >          \/ cons<N> <Cons>  `ofWeight`  <W>
-- >          \/ ...
--
-- /Warning:/ do not apply @ \`ofWeight\` 0 @ to recursive data structure
-- constructors.  In general this will make the list of size 0 infinite,
-- breaking the tier invariant (each tier must be finite).
--
-- @ \`ofWeight\` /n/ @ is equivalent to 'reset' followed
-- by @/n/@ applications of 'delay'.
ofWeight :: [[a]] -> Int -> [[a]]
ofWeight :: [[a]] -> Int -> [[a]]
ofWeight [[a]]
xss Int
w  =  ([a] -> Bool) -> [[a]] -> [[a]]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[a]]
xss [[a]] -> Int -> [[a]]
forall a. [[a]] -> Int -> [[a]]
`addWeight` Int
w

-- | Adds to the weight of a constructor or tiers.
--
-- > instance Listable <Type> where
-- >   tiers  =  ...
-- >          \/ cons<N> <Cons>  `addWeight`  <W>
-- >          \/ ...
--
-- Typically used as an infix operator when defining 'Listable' instances:
--
-- > > [ xs, ys, zs, ... ] `addWeight` 1
-- > [ [], xs, ys, zs, ... ]
--
-- > > [ xs, ys, zs, ... ] `addWeight` 2
-- > [ [], [], xs, ys, zs, ... ]
--
-- > > [ [], xs, ys, zs, ... ] `addWeight` 3
-- > [ [], [], [], [], xs, ys, zs, ... ]
--
-- @ \`addWeight\` /n/ @ is equivalent to @/n/@ applications of 'delay'.
addWeight :: [[a]] -> Int -> [[a]]
addWeight :: [[a]] -> Int -> [[a]]
addWeight [[a]]
xss Int
w  =  Int -> [a] -> [[a]]
forall a. Int -> a -> [a]
replicate Int
w [] [[a]] -> [[a]] -> [[a]]
forall a. [a] -> [a] -> [a]
++ [[a]]
xss