Mx      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ None 012345T[!the power set of a set of values.2(powerset2matrix . powerSet . Set.fromList) [1..3]*[[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]2(powerset2matrix . dropEach . Set.fromList) [1..3][[1,2],[1,3],[2,3]]Aconvert a power set to an isomorphic matrix, sorting the entries. (for doctest) (for doctest)      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~None,01234569:;DOQRT[ 8"Generic Enumerable", lifted to unary type constructors. wrap any (Bounded a, Enum a) to be a  Enumerable via .(avoids OverlappingInstances). Xenumerate the set of all values in a (finitely enumerable) type. enumerates depth first. generalizes 7s to any finite/discrete type. an Enumerable is either:an Enuma product of Enumerablesa sum of Enumerables)can be implemented automatically via its < instance.laws:finite:   /= _|_ consistent:   _ = -  so you can index the  $ with a nonnegative index below the  . distinct:  (Eq a) =>    ==   complete: x `elem'  coincides with Bounded Enums: ( a,  a) =>   ==  ( a) =>   == (Bounded2 constraint elided for convenience, but relevant.),("inputs" a type, outputs a list of values).Every type in base* (that can be an instance) is an instance.for non-< Bounded Enums: instance Enumerable _ where   = boundedEnumerated   =  for non-< Bounded Enums. Assuming C is correct, safely stop the enumeration (and know where to start).2behavior may be undefined when the cardinality of a# is larger than the cardinality of Int. this should be okay, as Int is at least as big as Int64;, which is at least as big as all the monomorphic types in base that instantiate Bounded. you can double-check with:AboundedCardinality (const(undefined::Int)) -- platform specific18446744073709551616 9-- i.e. 1 + 9223372036854775807 - (-9223372036854775808) /works with non-zero-based Enum instances, like Int64 or a custom toEnum/fromEnum=. assumes the enumeration's numbering is contiguous, e.g. if  fromEnum 0 and  fromEnum 2 both exist, then  fromEnum 1 should exist too.for non-< Enums: instance Enumerable ... where   = enumEnumerated !the enum should still be bounded.for non-< Bounded Indexed () types: instance Enumerable _ where   = indexedEnumerated   =  for non-< Bounded Indexed () types.\enumerate only when the cardinality is small enough. returns the cardinality when too large.)enumerateBelow 2 :: Either Natural [Bool]Left 2+enumerateBelow 100 :: Either Natural [Bool]Right [False,True]useful when you've established that traversing a list below some length and consuming its values is reasonable for your application. e.g. after benchmarking, you think you can process a billion entries within a minute.menumerate only when completely evaluating the list doesn't timeout (before the given number of microseconds).@enumerateTimeout (2 * 10^6) :: IO (Maybe [Bool]) -- two secondsJust [False,True]ignore datatype metadataignore constructor metadataignore selector metadataadd lists with (<>)multiply lists with  concatMapcall  singleton list empty list/the cardinality is a product of cardinalities. &(a can be any  Enumerable , unlike the Enum instance where a is an Integral).@the   is the cardinality of the  of a, i.e. 2^|a|@. warning: it grows quickly. don't try to take the power set of H ! or even .the  l call is efficient (depending on the efficiency of the base type's call). you should be able to safely call 1, unless the arithmetic itself becomes too large.enumerated :: [Set Bool]D[fromList [],fromList [False],fromList [False,True],fromList [True]]A7B6C5D4E3Fthe product type.the  ( is the product of the cardinalities of a and b.%cardinality ([] :: [(Bool,Ordering)])6H the sum type.the  $ is the sum of the cardinalities of a and b.*cardinality ([] :: [Either Bool Ordering])5I0there are only a million (1,114,112) characters.+import Data.Char (ord,chr) -- 'ord', 'chr' ord minBound0 ord maxBound1114111length [chr 0 ..]1114112K=1 + toInteger (maxBound::Int16) - toInteger (minBound::Int16)65536M -- ( prevents overflow);1 + toInteger (maxBound::Int8) - toInteger (minBound::Int8)256R (phantom in a)R  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUV S  VUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"! L   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVNone012345 WXYZ[\]^_`ab ba`_^]\[ZYXW WXYZ[\]^_`abNone ,012345DRdfinite but too large.91 + toInteger (maxBound::Int) - toInteger (minBound::Int)...ffinite but too large. 2^64 is over a billion billion.e.g.  ? (which takes time linear in the domain) on a function of type (:: Int -> Bool), won't terminate anytime soon.=1 + toInteger (maxBound::Int64) - toInteger (minBound::Int64)18446744000000000000hfinite but too large. 2^64 is a few billion.=1 + toInteger (maxBound::Int32) - toInteger (minBound::Int32) 4294967296cdefghhgfedccdefghNone012345Tijklmnopqrst ijklmnopqrst mnopijklqrstijklmnopqrstNone*,0123459:;DQRTua predicate, inclusive. > type CardinalityWithinAMillion a = CardinalityWithin 1000000 a > :kind! CardinalityWithinAMillion Bool True > :kind! CardinalityWithinAMillion Char False v1typechecks only when the constraint is satisifed. a constaint.x*a type is finite, i.e. has a bounded size.laws:consistent with Enumerate.Enumerable:  cardinality = zi.e. the value-level (a Z) matches the type-level (a )e.g.reifyCardinality ([]::[Bool])2zreifyCardinality ([]::[Bool])2{ b^a| 2^a}  a*b*c*d*e*f*g~  a*b*c*d*e*f  a*b*c*d*e a*b*c*d a*b*c a*b/the cardinality is a product of cardinalities. a + b 1 + a 1114112 2^16 2^16 2^8 2^8 3 2 1 0uvwxyz{|}~uvwxyzxy~}|{wzvuuvwxyz{|}~ None012345" ijklmnopqrstuvwxyzNone 01234579;[(for documentation)Kdemonstrates: empty type, unit type, product type, sum type, type variable.with .{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} , the derivation is a one-liner: 5data Demo a = ... deriving (Show,Generic,Enumerable) (for documentation) demoEnumerated = enumerated"_ <- traverse print demoEnumerated Demo1Demo2 False NothingDemo2 False (Just False)Demo2 False (Just True)Demo2 True NothingDemo2 True (Just False)Demo2 True (Just True) Demo3 False Demo3 TrueNone 01234579;[    !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./01234567898:8;8<=>?@ABCBDBEBFBGBHBIBJBKBLBMBNBOBPQRQSQTQUQVWXYZY[Y\Y]^_`abcbdbebfbgbhbijklmnobpbqbrbstbubvwxwywz{|}~}QQBBBBBBBBBBw88888      !"#$%&'()*+,-./0123456789:;<=>?=@ABCDBCEFGHFGIJKLJKMJKNOPQOPROPSOPTOPUOPVOPWOPXOPYOPZOP[OP\OP]OP^OP_OP`OPaOPbOPcOPdOPeOPfOPgOPhOPiOPjOPkOPlOPmOPnOPoOPpOPqOPrOPsOPtOPuOPvOPwOPxOPyOPzOP{OP|OP}OP~OPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPOPb&enumerate-0.2.2-GLNw96DavM81ig8hsrFpXPEnumerate.ExtraEnumerate.TypesEnumerate.Orphans.GHCEnumerate.Orphans.LargeEnumerate.EnumEnumerate.CardinalityEnumerate.ExampleEnumerate.Test Enumerate reifyFunction int2naturalpowerSetdropEachpowerset2matrix printMappings GEnumerable genumerated gcardinalityWrappedBoundedEnumunwrapBoundedEnum Enumerable enumerated cardinalityboundedEnumeratedboundedCardinalityenumEnumeratedindexedEnumeratedindexedCardinalityenumerateBelowenumerateTimeout$fGEnumerableM1$fGEnumerableM10$fGEnumerableM11$fGEnumerable:+:$fGEnumerable:*:$fGEnumerableK1$fGEnumerableU1$fGEnumerableV1$fEnumerableRec$fEnumerableRec0$fEnumerableWrappedBoundedEnum$fEnumerableAssociativity$fEnumerableCUShort$fEnumerableCShort$fEnumerableCUChar$fEnumerableCSChar$fEnumerableCWchar$fEnumerableCChar$fEnumerableComplex$fEnumerableAlt$fEnumerableEndo$fEnumerableProduct$fEnumerableSum$fEnumerableLast$fEnumerableFirst$fEnumerableDual$fEnumerableAny$fEnumerableAll$fEnumerableFormatSign$fEnumerableFormatAdjustment$fEnumerableNewlineMode$fEnumerableNewline$fEnumerableDeadlock#$fEnumerableAllocationLimitExceeded$$fEnumerableBlockedIndefinitelyOnSTM%$fEnumerableBlockedIndefinitelyOnMVar$fEnumerableNestedAtomically$fEnumerableNonTermination$fEnumerableAsyncException$fEnumerableArithException$fEnumerableSeekMode$fEnumerableIOMode$fEnumerableGeneralCategory$fEnumerableSet$fEnumerable(,,,,,,)$fEnumerable(,,,,,)$fEnumerable(,,,,)$fEnumerable(,,,)$fEnumerable(,,)$fEnumerable(,)$fEnumerableMaybe$fEnumerableEither$fEnumerableChar$fEnumerableWord16$fEnumerableInt16$fEnumerableWord8$fEnumerableInt8$fEnumerableCoercion$fEnumerable:~:$fEnumerableConst$fEnumerableIdentity$fEnumerableProxy$fEnumerableOrdering$fEnumerableBool$fEnumerable()$fEnumerableVoid$fEnumerableGiveGCStats$fEnumerableDoCostCentres$fEnumerableDoHeapProfile$fEnumerableDoTrace$fEnumerableCodingProgress$fEnumerableCodingFailureMode$fEnumerableIODeviceType$fEnumerableBufferState $fEnumerableSpecConstrAnnotation$fEnumerableDown$fEnumerableCMode$fEnumerableCIno$fEnumerableWord$fEnumerableInt$fEnumerableWord64$fEnumerableInt64$fEnumerableWord32$fEnumerableInt32minBound_enumerable'maxBound_enumerable'toEnum_enumerable'fromEnum_enumerable'minBound_enumerablemaxBound_enumerabletoEnum_enumerablefromEnum_enumerablearray_enumerabletable_enumerable toEnumDefaultfromEnumDefaultIsCardinalityWithinCardinalityWithin GCardinalityFinite CardinalityreifyCardinality $fFinite(->) $fFiniteSet$fFinite(,,,,,,)$fFinite(,,,,,)$fFinite(,,,,) $fFinite(,,,) $fFinite(,,) $fFinite(,) $fFiniteRec $fFiniteRec0$fFiniteEither $fFiniteMaybe $fFiniteChar$fFiniteWord16 $fFiniteInt16 $fFiniteWord8 $fFiniteInt8 $fFiniteProxy$fFiniteOrdering $fFiniteBool $fFinite() $fFiniteVoidAA0A1A2A3DemoDemo0Demo1Demo2Demo3maindemoEnumeratedarray_DemoBooltable_DemoBool $fEnumDemo $fBoundedDemo $fShowDemo$fEqDemo $fOrdDemo $fGenericDemo$fEnumerableDemo$fShowA $fGenericA $fEnumerableABB0B1B2B3things$fEnumB $fBoundedB$fShowB$fEqB$fOrdB $fGenericB $fEnumerableBbaseGHC.Base++ghc-primGHC.PrimseqGHC.Listfilterzip System.IOprint Data.Tuplefstsnd otherwisemap$GHC.Real fromIntegral realToFracGHC.EnumBoundedminBoundmaxBoundEnumenumFrom enumFromThenenumFromThenTo enumFromTofromEnumsuccpred GHC.ClassesEq==/= GHC.FloatFloatingpiexplogsqrt**logBasesincostanasinacosatansinhcoshtanhasinhacoshatanh Fractional fromRational/recipIntegral toIntegerquotremdivmodquotRemdivModMonad>>=>>returnfail Data.DataDataFunctorfmap<$GHC.NumNum*+-negate fromIntegerabssignumOrd>=minmax<=compareGHC.ReadRead readsPrecreadListReal toRational RealFloat floatRadix floatDigits floatRange decodeFloat encodeFloatexponent significand scaleFloatisNaN isInfiniteisDenormalizedisNegativeZeroisIEEEatan2RealFracproperFractiontruncateroundceilingfloorGHC.ShowShow showsPrecshowshowList Applicativepure<*>*><* Data.FoldableFoldablefoldrfoldMapnulllengthfoldlfoldl'foldl1sumproductfoldr1maximumminimumelemData.Traversable TraversabletraversemapM sequenceAsequence GHC.GenericsGenericData.Semigroup Semigroup<>sconcatstimesMonoidmemptymappendmconcat GHC.TypesBoolFalseTrueCharDoubleFloatInt integer-gmpGHC.Integer.TypeIntegerMaybeNothingJustOrderingLTEQGTRationalIOWord Data.EitherEitherLeftRight GHC.NaturalNaturalControl.Monad.IO.ClassMonadIOliftIO Data.ListisSubsequenceOf mapAccumR mapAccumLControl.Applicativeoptional WrappedMonad WrapMonad unwrapMonad WrappedArrow WrapArrow unwrapArrowZipList getZipListControl.Category>>><<<readIOreadLn appendFile writeFilereadFileinteract getContentsgetLinegetCharputStrLnputStrputChar Text.ReadreadsGHC.IO.ExceptionioErrorData.Functor.ConstConstgetConstnotElemallanyorand concatMapconcat sequence_mapM_ traverse_GHC.IOFilePath userErrorIOErroreither Data.ProxyProxy Data.OldListunwordswordsunlineslinesunfoldrsortOnsortBysort permutations subsequencestailsinitsgroupBygroupdeleteFirstsByunzip7unzip6unzip5unzip4zipWith7zipWith6zipWith5zipWith4zip7zip6zip5zip4genericReplicate genericIndexgenericSplitAt genericDrop genericTake genericLengthinsertByinsert partition transpose intercalate intersperse intersectBy intersectunionByunion\\deleteBydeletenubBynub isInfixOf isSuffixOf isPrefixOf findIndices findIndex elemIndices elemIndex stripPrefix dropWhileEndlex readParenText.ParserCombinators.ReadPReadS Data.Function&on Data.Functor<$>lcmgcd^^^oddeven showParen showStringshowCharshowsShowSunzip3unzipzipWith3zipWithzip3!!lookupreversebreakspansplitAtdroptake dropWhile takeWhilecycle replicaterepeatiteratescanr1scanrscanl'scanl1scanlfoldl1'initlasttailunconshead Data.MaybemaybeuncurrycurrysubtractasTypeOfuntil$!flip.constid=<<liftA3liftA2liftA<**> Alternativeempty<|>somemanyStringGHC.ErrerrorWithoutStackTrace&&||notcontainers-0.5.7.1 Data.Map.BaseMap Data.Set.BaseSet1data-default-class-0.1.2.0-FYQpjIylblBDctdkHAFeXAData.Default.ClassDefaultdefdeepseq-1.4.2.0Control.DeepSeqNFDatarnf'hashable-1.2.6.0-EikjbjmXLfl2FtsVIjLwnCData.Hashable.ClassHashable hashWithSalthash"safe-0.3.14-ALdwhNEer7fKnF5VYCbXfHSafepredSafepredNotepredDefpredMaysuccSafesuccNotesuccDefsuccMay toEnumSafe toEnumNote toEnumDef toEnumMayfindIndexJustNotefindIndexJustDef findIndexJustelemIndexJustNoteelemIndexJustDef elemIndexJust findJustNote findJustDeffindJustlookupJustNote lookupJustDef lookupJustreadNotereadDefreadMayreadEitherSafeatNoteatDefatMayat assertNote fromJustNote fromJustDef cycleNotecycleDefcycleMay scanl1Note scanr1Note scanl1Def scanr1Def scanl1May scanr1May foldl1Note' foldl1Note foldr1Note foldl1Def' foldl1Def foldr1Def foldl1May' foldl1May foldr1May maximumByNote minimumByNote maximumByDef minimumByDef maximumByMay minimumByMay maximumNote minimumNote maximumDef minimumDef maximumMay minimumMaylastNoteheadNotelastDefheadDeflastMayheadMayinitSafeinitNoteinitDefinitMaytailSafetailNotetailDeftailMayabort#text-1.2.2.1-9Yh8rJoh8fO2JMLWffT3QsData.Text.Internal.LazyText#spiros-0.0.0-1m4EQOVufCI2o9MHC7fcFUSpiros.UtilitiesiorstriplstripstripdelayMillisecondsforkever forkever_ list2maybe maybe2list either2bool either2maybe maybe2either maybe2boolnothing__BUG__todoIP:.<&>indextoInt$>snoc-: greaterThanlessThan<>CanInterpolate:~>:.:GHC.ArrIxGHC.WordWord8 __fromJust____bug__nat2intNat