<commit_before>-- |
-- Module      : Test.LeanCheck.CoListable
-- Copyright   : (c) 2015-2017 <NAME>
-- License     : 3-Clause BSD  (see the file LICENSE)
-- Maintainer  : <NAME> <<EMAIL>>
--
-- This module is part of LeanCheck,
-- a simple enumerative property-based testing library.
--
-- This module exports a 'Listable' instance for function enumeration by means
-- of a 'CoListable' typeclass.
--
-- This module /does not currently work/, it it just a sketch and a stub.
module Test.LeanCheck.Function.CoListable
where


import Test.LeanCheck
import Test.LeanCheck.Tiers
import Test.LeanCheck.Utils (Nat(..), Nat2(..), Nat3(..))
import Data.Maybe (fromMaybe)


instance (CoListable a, Listable b) => Listable (a -> b) where
  tiers = cotiers tiers


(\+:/) :: [[a]] -> [[a]] -> [[a]]
xss \+:/ yss = xss \/ ([]:yss)
infixr 9 \+:/


class CoListable a where
  cotiers :: [[b]] -> [[a -> b]]


instance CoListable () where
  cotiers rs = mapT (\r  () -> r) rs


instance CoListable Bool where
  cotiers rs = productWith (\r1 r2  b -> if b then r1 else r2) rs rs


instance CoListable a => CoListable (Maybe a) where
  cotiers rs = productWith (\z f  m -> case m of
                                         Nothing -> z
                                         Just x  -> f x) rs (cotiers rs)


instance (CoListable a, CoListable b) => CoListable (Either a b) where
  cotiers rs = productWith (\f g  e -> case e of
                                         Left x  -> f x
                                         Right x -> g x) (cotiers rs) (cotiers rs)


instance (CoListable a) => CoListable [a] where
  cotiers rss = mapT const rss
           \+:/ productWith
                  (\y f  xs -> case xs of
                                 []      -> y
                                 (x:xs') -> f x xs')
                  rss
                  (cotiers (cotiers rss))


instance (CoListable a, CoListable b) => CoListable (a,b) where
  cotiers = mapT uncurry . cotiers . cotiers


instance CoListable Int where
  cotiers rss = mapT const rss
           \+:/ productWith
                  (\f g  i -> if i >= 0 then f (i-1) else g (i+1))
                  (cotiers rss) (cotiers rss)

instance CoListable Nat where
  cotiers rss = mapT const rss
           \+:/ productWith
                  (\f g  i -> if even i then f (i`div`2) else g (i`div`2))
                  (cotiers rss) (cotiers rss)
-- TODO: fix the above instance, there are no negative Nat's

instance CoListable Nat2 where
  cotiers rss = (\rs x -> rs !! fromIntegral x) `mapT` products [rss,rss]

instance CoListable Nat3 where
  cotiers rss = (\rs x -> rs !! fromIntegral x) `mapT` products [rss,rss,rss]


alts0 :: [[a]] -> [[a]]
alts0 = id

alts1 :: CoListable a => [[b]] -> [[a->b]]
alts1 bs = cotiers bs

alts2 :: (CoListable a, CoListable b) => [[c]] -> [[a->b->c]]<commit_msg>Function.CoListable: Remove TODO<commit_after>-- |
-- Module      : Test.LeanCheck.CoListable
-- Copyright   : (c) 2015-2017 <NAME>
-- License     : 3-Clause BSD  (see the file LICENSE)
-- Maintainer  : <NAME> <<EMAIL>>
--
-- This module is part of LeanCheck,
-- a simple enumerative property-based testing library.
--
-- This module exports a 'Listable' instance for function enumeration by means
-- of a 'CoListable' typeclass.
--
-- This module /does not currently work/, it it just a sketch and a stub.
module Test.LeanCheck.Function.CoListable
where


import Test.LeanCheck
import Test.LeanCheck.Tiers
import Test.LeanCheck.Utils (Nat(..), Nat2(..), Nat3(..))
import Data.Maybe (fromMaybe)


instance (CoListable a, Listable b) => Listable (a -> b) where
  tiers = cotiers tiers


(\+:/) :: [[a]] -> [[a]] -> [[a]]
xss \+:/ yss = xss \/ ([]:yss)
infixr 9 \+:/


class CoListable a where
  cotiers :: [[b]] -> [[a -> b]]


instance CoListable () where
  cotiers rs = mapT (\r  () -> r) rs


instance CoListable Bool where
  cotiers rs = productWith (\r1 r2  b -> if b then r1 else r2) rs rs


instance CoListable a => CoListable (Maybe a) where
  cotiers rs = productWith (\z f  m -> case m of
                                         Nothing -> z
                                         Just x  -> f x) rs (cotiers rs)


instance (CoListable a, CoListable b) => CoListable (Either a b) where
  cotiers rs = productWith (\f g  e -> case e of
                                         Left x  -> f x
                                         Right x -> g x) (cotiers rs) (cotiers rs)


instance (CoListable a) => CoListable [a] where
  cotiers rss = mapT const rss
           \+:/ productWith
                  (\y f  xs -> case xs of
                                 []      -> y
                                 (x:xs') -> f x xs')
                  rss
                  (cotiers (cotiers rss))


instance (CoListable a, CoListable b) => CoListable (a,b) where
  cotiers = mapT uncurry . cotiers . cotiers


instance CoListable Int where
  cotiers rss = mapT const rss
           \+:/ productWith
                  (\f g  i -> if i >= 0 then f (i-1) else g (i+1))
                  (cotiers rss) (cotiers rss)

instance CoListable Nat where
  cotiers rss = mapT const rss
           \+:/ productWith
                  (\f g  i -> if even i then f (i`div`2) else g (i`div`2))
                  (cotiers rss) (cotiers rss)

instance CoListable Nat2 where
  cotiers rss = (\rs x -> rs !! fromIntegral x) `mapT` products [rss,rss]

instance CoListable Nat3 where
  cotiers rss = (\rs x -> rs !! fromIntegral x) `mapT` products [rss,rss,rss]


alts0 :: [[a]] -> [[a]]
alts0 = id

alts1 :: CoListable a => [[b]] -> [[a->b]]
alts1 bs = cotiers bs

alts2 :: (CoListable a, CoListable b) => [[c]] -> [[a->b->c]]
{'fraction_non_alphanumeric': 0.13207213578500707, 'fraction_numerical': 0.009900990099009901, 'mean_word_length': 1.867207298530157, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6707679', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1788, 'n_words': 663}