Hoogle Search

Within LTS Haskell 24.45 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. type ConflictMap = Map Var QPN Int

    cabal-install-solver Distribution.Solver.Modular.ConflictSet

    No documentation available.

  2. type ConflictMap = Map Var QPN Int

    cabal-install-solver Distribution.Solver.Modular.Dependency

    No documentation available.

  3. type RevDepMap = Map QPN [(Component, QPN)]

    cabal-install-solver Distribution.Solver.Modular.Dependency

    A map containing reverse dependencies between qualified package names.

  4. data OptionalStanzaMap a

    cabal-install-solver Distribution.Solver.Types.OptionalStanza

    Note: this is total map.

  5. imapSubvectors :: (Vector u a, Vector v b) => (Word -> u a -> v b) -> Chimera u a -> Chimera v b

    chimera Data.Chimera

    Map subvectors of a stream, using a given length-preserving function. The first argument of the function is the index of the first element of subvector in the Chimera.

  6. module Data.Chimera.ContinuousMapping

    Helpers for continuous mappings, useful to memoize functions on Int (instead of Word only) and functions over two and three arguments. Example 1 Imagine writing a program to simulate Rule 90. This is a cellular automaton, which consists of an infinite one-dimensional line of cells, each being either dead (False) or alive (True). If two neighbours of a cell are equal, it becomes dead on the next step, otherwise alive. Usually cellular automata are modelled by a finite vector. This is a bit suboptimal, because cellular automata may grow in different directions over time, but with a finite vector one has to define a bounding segment well beforehand. Moreover, what if we are interested to explore an evolution of an essentially infinite initial configuration? It would be natural to encode an initial configuration as a function Int -> Bool, which takes a coordinate and returns the status of the corresponding cell. Define a function, which translates the automaton to the next step:

    step :: (Int -> Bool) -> (Int -> Bool)
    step current = \n -> current (n - 1) /= current (n + 1)
    
    Unfortunately, iterating step would be extremely slow because of branching recursion. One could suggest to introduce a caching layer:
    step :: (Int -> Bool) -> (Int -> Bool)
    step current = \n -> current' (n - 1) /= current' (n + 1)
    where
    current' = memoize (current . fromIntegral) . fromIntegral
    
    Unfortunately, it would not work well, because fromIntegral :: Int -> Word maps -1 to maxBound and it would take ages to memoize everything up to maxBound. But continuous mappings intToWord and wordToInt avoid this issue:
    step :: (Int -> Bool) -> (Int -> Bool)
    step current = \n -> current' (n - 1) /= current' (n + 1)
    where
    current' = memoize (current . wordToInt) . intToWord
    
    Example 2 What about another famous cellular automaton: Conway's Game of Life? It is two-dimensional, so its state can be represented as a function Int -> Int -> Bool. Following the approach above, we would like to memoize such functions. Namely, cast the state to Word -> Bool, ready for memoization:
    cast :: (Int -> Int -> Bool) -> (Word -> Bool)
    cast f = \n -> let (x, y) = fromZCurve n in f (fromHalf x) (fromHalf y)
    where
    fromHalf :: HalfWord -> Int
    fromHalf = wordToInt . fromIntegral @HalfWord @Word
    
    and then back:
    uncast :: (Word -> Bool) -> (Int -> Int -> Bool)
    uncast g = \x y -> g (toZCurve (toHalf x) (toHalf y))
    where
    toHalf :: Int -> HalfWord
    toHalf = fromIntegral @Word @HalfWord . intToWord
    

  7. module Data.Chimera.WheelMapping

    Helpers for mapping to rough numbers and back. This has various applications in number theory. Example Let isPrime be an expensive predicate, which checks whether its argument is a prime number. We can memoize it as usual:

    isPrimeCache1 :: UChimera Bool
    isPrimeCache1 = tabulate isPrime
    
    isPrime1 :: Word -> Bool
    isPrime1 = index isPrimeCache1
    
    But one may argue that since the only even prime number is 2, it is quite wasteful to cache isPrime for even arguments. So we can save half the space by memoizing it for odd numbers only:
    isPrimeCache2 :: UChimera Bool
    isPrimeCache2 = tabulate (isPrime . (\n -> 2 * n + 1))
    
    isPrime2 :: Word -> Bool
    isPrime2 n
    | n == 2    = True
    | even n    = False
    | otherwise = index isPrimeCache2 ((n - 1) `quot` 2)
    
    Here \n -> 2 * n + 1 maps n to the (n+1)-th odd number, and \n -> (n - 1) `quot` 2 takes it back. These functions are available below as fromWheel2 and toWheel2. Odd numbers are the simplest example of numbers, lacking small prime factors (so called rough numbers). Removing numbers, having small prime factors, is sometimes called wheel sieving. One can go further and exclude not only even numbers, but also integers, divisible by 3. To do this we need a function which maps n to the (n+1)-th number coprime with 2 and 3 (thus, with 6) and its inverse: namely, fromWheel6 and toWheel6. Then write
    isPrimeCache6 :: UChimera Bool
    isPrimeCache6 = tabulate (isPrime . fromWheel6)
    
    isPrime6 :: Word -> Bool
    isPrime6 n
    | n `elem` [2, 3] = True
    | n `gcd` 6 /= 1  = False
    | otherwise       = index isPrimeCache6 (toWheel6 n)
    
    Thus, the wheel of 6 saves more space, improving memory locality. (If you need to reduce memory consumption even further, consider using Bit wrapper, which provides an instance of unboxed vector, packing one boolean per bit instead of one boolean per byte for Bool)

  8. bitCoerceMap :: (BitPack a, BitPack b, BitSize a ~ BitSize b) => (a -> a) -> b -> b

    clash-prelude Clash.Class.BitPack

    Map a value by first coercing to another type through its bit representation.

    >>> pack (-5 :: Signed 32)
    0b1111_1111_1111_1111_1111_1111_1111_1011
    
    >>> bitCoerceMap @(Vec 4 (BitVector 8)) (replace 1 0) (-5 :: Signed 32)
    -16711685
    
    >>> pack (-16711685 :: Signed 32)
    0b1111_1111_0000_0000_1111_1111_1111_1011
    

  9. bitCoerceMap :: (BitPack a, BitPack b, BitSize a ~ BitSize b) => (a -> a) -> b -> b

    clash-prelude Clash.Class.BitPack.Internal

    Map a value by first coercing to another type through its bit representation.

    >>> pack (-5 :: Signed 32)
    0b1111_1111_1111_1111_1111_1111_1111_1011
    
    >>> bitCoerceMap @(Vec 4 (BitVector 8)) (replace 1 0) (-5 :: Signed 32)
    -16711685
    
    >>> pack (-16711685 :: Signed 32)
    0b1111_1111_0000_0000_1111_1111_1111_1011
    

  10. concatMap :: forall a (m :: Nat) b (n :: Nat) . (a -> Vec m b) -> Vec n a -> Vec (n * m) b

    clash-prelude Clash.Explicit.Prelude

    Map a function over all the elements of a vector and concatentate the resulting vectors.

    >>> concatMap (replicate d3) (1:>2:>3:>Nil)
    1 :> 1 :> 1 :> 2 :> 2 :> 2 :> 3 :> 3 :> 3 :> Nil
    

Page 1020 of many | Previous | Next