| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Enumerate.Function
Description
orphan instances, of 'Enumerate'\/'Eq'\/'Show', for functions.
(that are included for completeness, but not exported by default (i.e. by Data.Enumerate). you probably want build-time instance-resolution errors rather than possible runtime non-termination).
-- doctest
>>>:set -XLambdaCase>>>let printMappings mappings = traverse (\mapping -> (putStrLn"") >> (traverse print) mapping) mappings >> return()
- unsafeFromList :: Ord a => [(a, b)] -> a -> b
- functionEnumerated :: (Enumerable a, Enumerable b, Ord a, Ord b) => [a -> b]
- mappingEnumeratedAt :: [a] -> [b] -> [[(a, b)]]
- crossProduct :: [a] -> [b] -> [[(a, b)]]
Documentation
unsafeFromList :: Ord a => [(a, b)] -> a -> b Source
wraps lookup
>>>(unsafeFromList [(False,True),(True,False)]) FalseTrue>>>(unsafeFromList [(False,True),(True,False)]) TrueFalse
functionEnumerated :: (Enumerable a, Enumerable b, Ord a, Ord b) => [a -> b] Source
mappingEnumeratedAt :: [a] -> [b] -> [[(a, b)]] Source
[(a,b)] is a mapping, [[(a,b)]] is a list of mappings.
>>>let orderingPredicates = mappingEnumeratedAt [LT,EQ,GT] [False,True]>>>print $ length orderingPredicates8>>>printMappings $ orderingPredicates(LT,False) (EQ,False) (GT,False) (LT,False) (EQ,False) (GT,True) (LT,False) (EQ,True) (GT,False) (LT,False) (EQ,True) (GT,True) (LT,True) (EQ,False) (GT,False) (LT,True) (EQ,False) (GT,True) (LT,True) (EQ,True) (GT,False) (LT,True) (EQ,True) (GT,True) (LT,False) (EQ,False) (GT,False) (LT,False) (EQ,False) (GT,True) (LT,False) (EQ,True) (GT,False) (LT,False) (EQ,True) (GT,True) (LT,True) (EQ,False) (GT,False) (LT,True) (EQ,False) (GT,True) (LT,True) (EQ,True) (GT,False) (LT,True) (EQ,True) (GT,True)
where the (total) mapping:
(LT,False) (EQ,False) (GT,True)
is equivalent to the function:
\case LT -> False EQ -> False GT -> True
crossProduct :: [a] -> [b] -> [[(a, b)]] Source
>>>let crossOrderingBoolean = crossProduct [LT,EQ,GT] [False,True]>>>printMappings $ crossOrderingBoolean>>>(LT,False) (LT,True) (EQ,False) (EQ,True) (GT,False) (GT,True)
the length of the outer list is the size of the first set and the length of the inner list is the size of the second set.
>>>print $ length crossOrderingBoolean3>>>print $ length (head crossOrderingBoolean)2