Aelve Codesearch

grep over package repositories
Please provide a string to search for.
3+ characters are required.
Index updated about a month ago

total matches: more than 1000

3d-graphics-examples-0.0.0.2
4 matches
src/mountains/Mountains.hs
    initGen = mkStdGen (terrainNumber curState)
    (matrix, _) = (allTerrainSteps initGen) !! (iteration curState)
    matrix' = if (flattenWater curState)
      then map (map (flat)) matrix else matrix

  if (renderingRequired curState)
    then defineList (DisplayList 1) CompileAndExecute $ do
      blend $= Disabled
      drawTerrain (drawMode curState) (-d,-d) (d,d) $ enlargeTerrain matrix'

            
src/mountains/Mountains.hs
--
terrainRandomFunc :: RandomGen gen => Distribution -> Int -> gen -> Double
  -> ([Double], gen)
terrainRandomFunc distrib n gen var = (map fst $ tail ls, nextGen)
  where
    (_, nextGen) = last ls
    ls = (0, gen) : (take n $ distribFunc gen var)
    distribFunc = case distrib of
      UniformDistribution -> allUniforms

            
src/mountains/Mountains.hs
      (zipWith interleave squares2 diamonds)

    squares2 = zipWith4 squareStep
      hss (map lastAndInit diamonds) (tailAndHead hss)
      (dsSquares2 `inGroupsOf` nx)

    squares1 = zipWith4 squareStep
      (lastAndInit diamonds) hss diamonds (dsSquares1 `inGroupsOf` nx)


            
src/mountains/Mountains.hs

-- Erweitert Terrain um den redundanten oberen und rechten Rand
enlargeTerrain :: [[Double]] -> [[Double]]
enlargeTerrain hss = map enlarge (enlarge hss)
  where
    enlarge = \cs -> if null cs then [] else cs ++ [head cs]

            
4Blocks-0.2
4 matches
Core/ColouredPoint.hs
convertColouredToSimplePoint (x,y,c) = (x,y)

convertColouredToSimplePoints :: [ColouredPoint] -> [SimplePoint]
convertColouredToSimplePoints xs = map (convertColouredToSimplePoint) xs

moveColouredPointDown :: ColouredPoint -> ColouredPoint
moveColouredPointDown (x,y,c) = (x,y-1,c)

moveColouredPointUp :: ColouredPoint -> ColouredPoint

            
Core/ColouredPoint.hs
  where 
    sortedByYColouredPoints = sortBy (compare `on` getColouredPointY) colouredPoints
    groupedColouredPoints = groupBy (\(x1,y1,c1) (x2,y2,c2) -> (y1==y2)) sortedByYColouredPoints
    sortedByXYColouredPointsLines = map (sortBy (compare `on` getColouredPointX)) groupedColouredPoints
    reversedGroupedColouredPoints = reverse sortedByXYColouredPointsLines
    linesOfColouredPoints = reversedGroupedColouredPoints
    
getColumnsOfColouredPoints :: [ColouredPoint] -> [[ColouredPoint]]
getColumnsOfColouredPoints colouredPoints = columnsOfColouredPoints

            
Core/ColouredPoint.hs
  where
    sortedByXColouredPoints = sortBy (compare `on` getColouredPointX) colouredPoints
    groupedColouredPoints = groupBy (\(x1,y1,c1) (x2,y2,c2) -> (x1==x2)) sortedByXColouredPoints
    sortedByXYColouredPointsLines = map (sortBy (compare `on` getColouredPointY)) groupedColouredPoints
    columnsOfColouredPoints = sortedByXYColouredPointsLines
    
getColouredPointsFromLines :: [[ColouredPoint]] -> [ColouredPoint]
getColouredPointsFromLines = concat


            
Core/ColouredPoint.hs
convertAllColouredPointsToColour :: Colour -> [ColouredPoint] -> [ColouredPoint]
convertAllColouredPointsToColour c colouredPoints = unColouredPoints ++ filteredColouredPoints
  where (filteredColouredPoints,removedColouredPoints) = extractColouredPoints Grey_Colour colouredPoints 
        unColouredPoints = map (convertAllColouredPointToColour c) removedColouredPoints

convertAllColouredPointToColour :: Colour -> ColouredPoint -> ColouredPoint
convertAllColouredPointToColour c (x,y,_) = (x,y,c)

            
ABList-0.0.3
2 matches
src/Data/AbList.hs
abFromListEither :: [Either a b] -> Maybe (AbList a b)
abFromListEither [] = Just AbNil
abFromListEither (Left a : []) = Just $ a :/ AbNil
abFromListEither (Left a : Right b : xs) = fmap (\t -> a :/ b :/ t) (abFromListEither xs)
abFromListEither _ = Nothing

abHead :: AbList a b -> Maybe a
abHead = abShallowFold Nothing $ const . Just


            
src/Data/AbList.hs

-- right-biased functor
instance Functor (AbList a) where
  fmap = abMapRights


            
AC-Colour-1.1.6
7 matches
Data/Colour/Double.hs
  Apply a function to every channel in a colour. (Mostly used
  internally, but exposed here in case it may be useful.)
-}
cmap :: (Double -> Double) -> Colour -> Colour
cmap f (Colour r g b) = Colour (f r) (f g) (f b)

{- |
  This is similar to 'Data.List.zipWith'. (Mostly used internally,
  but exposed here in case it may be useful.)
-}

            
Data/Colour/Double.hs
  brightness while not affecting the shade.)
-}
cscale :: Double -> Colour -> Colour
cscale x = cmap (x*)

instance Num Colour where
  (+) = czip (+)
  (-) = czip (-)
  (*) = czip (*)

            
Data/Colour/Double.hs
  (+) = czip (+)
  (-) = czip (-)
  (*) = czip (*)
  negate = cmap negate
  abs    = cmap abs
  signum = cmap signum
  fromInteger = grey . fromInteger

instance Fractional Colour where
  (/) = czip (/)
  recip = cmap recip

            
Data/Colour/Double.hs

instance Fractional Colour where
  (/) = czip (/)
  recip = cmap recip
  fromRational = grey . fromRational

{- |
  Take a @Colour@ and clip all channels to the range 0--1
  inclusive. Any value outside that range will be replaced

            
Data/Colour/Double.hs
  the range are unaffected.
-}
clip :: Colour -> Colour
clip = cmap (min 1 . max 0)

-- | Convert a 'Colour' into a tuple.
unpack :: Colour -> (Double, Double, Double)
unpack (Colour r g b) = (r, g, b)


            
Data/Colour/Word8.hs
  Apply a function to every channel of a @Colour8@. (Mostly used
  internally; exposed here in case it might be useful.)
-}
c8map :: (Word8 -> Word8) -> Colour8 -> Colour8
c8map f (Colour8 r g b) = Colour8 (f r) (f g) (f b)

{- |
  The colour equivilent of 'Data.List.zipWith'. (Mostly used
  internally; exposed here in case it might be useful.)
-}

            
Data/Colour/Word8.hs
  (+) = c8zip (+)
  (-) = c8zip (-)
  (*) = c8zip (\x y -> let (x', y') = (fromIntegral x, fromIntegral y) :: (Word16, Word16) in fromIntegral (x' * y' `div` 0x00FF))
  negate = c8map negate
  abs    = c8map abs
  signum = c8map signum
  fromInteger = grey8 . fromInteger

-- | Convert a 'Colour8' to a tuple.
unpack8 :: Colour8 -> (Word8, Word8, Word8)
unpack8 (Colour8 r g b) = (r,g,b)

            
AC-MiniTest-1.1.1
1 matches
Test/AC/Test.hs
  problem. You can solve it in several ways. One idea might be

  >t_size :: Test
  >t_size = tests $ map p_size [ [], [5], [5,5], [4,6], [1..10] ]

  Because this package doesn't deal with test data generation, you
  are free to use any approach you like. In particular, different
  properties can be tested with different test data (rather than
  relying on the type system to select test data for you), the data

            
AC-Vector-2.3.2
3 matches
Data/Vector/Class.hs
-}
class BasicVector v where
  -- | Apply a function to all vector fields.
  vmap    :: (Scalar -> Scalar) -> (v -> v)

  -- | Zip two vectors together field-by-field using the supplied function (in the style of @Data.List.zipWith@).
  vzip    :: (Scalar -> Scalar -> Scalar) -> (v -> v -> v)

  -- | Reduce a vector down to a single value using the supplied binary operator. The ordering in which this happens isn't guaranteed, so the operator should probably be associative and commutative.

            
Data/Vector/Class.hs
  The @(*|)@ and @(|*)@ operators are identical, but with their argument flipped. Just remember that the \'@|@\' denotes the scalar part.
-}
(*|) :: Vector v => Scalar -> v -> v
k *| v = vmap (k*) v

{- |
  Scale a vector (i.e., change its length but not its direction). This operator has the same precedence as the usual @(*)@ operator.

  The @(*|)@ and @(|*)@ operators are identical, but with their argument flipped. Just remember that the \'@|@\' denotes the scalar part.

            
Data/Vector/Class.hs
  The @(*|)@ and @(|*)@ operators are identical, but with their argument flipped. Just remember that the \'@|@\' denotes the scalar part.
-}
(|*) :: Vector v => v -> Scalar -> v
v |* k = vmap (k*) v

{- |
  Scale a vector (i.e., change its length but not its direction). This operator has the same precedence as the usual @(/)@ operator.

  The @(/|)@ and @(|/)@ operators are identical, but with their argument flipped. Just remember that the \'@|@\' denotes the scalar part.

            
ACME-0.0.0.1
8 matches
Acme/Cipher.hs

-- | The Playfair cipher
playfair = Cipher start start where
	start k = fn (take 25 (nub (map (\ch -> if ch == 'J' then 'I' else ch) k)) ++ (['A'..'Z'] \\ ('J' : k)))
	fn k (c1 : c2 : s) = (k !! (5 * n + y)) : (k !! (5 * x + m)) : fn k s
		where
			(n, m) = fromJust (findIndex (==c1) k) `divMod` 5
			(x, y) = fromJust (findIndex (==c2) k) `divMod` 5
	fn _ s = s

            
Acme/Cipher.hs
swap (x, y) = (y, x)

-- | The letter substitution cipher
substitution = Cipher (\k s -> map (\ch -> fromJust $ lookup ch k) s) (\k s -> map (\ch -> fromJust $ lookup ch (map swap k)) s)

letter x = ord x - ord 'A' + 1

letter2 x = chr (x + ord 'A' - 1)


            
Acme/Cipher.hs
viginere = Cipher (\k s -> zipWith addLetters s (cycle k)) (\k s -> zipWith subtractLetters s (cycle k))

-- | The Caesar cipher
caesar = Cipher (\k s -> map (`addLetters` k) s) (\k s -> map (`subtractLetters` k) s)

-- | For good measure, the German Enigma
data Rotor s = Rotor { mapping :: [(Char, Char)], position :: STRef s Char, nextRotor :: Maybe (Rotor s) }

advance rotor = do
	pos <- readSTRef (position rotor)
	let plus1 = addLetters pos 'A'
	writeSTRef (position rotor) plus1

            
Acme/Cipher.hs
	writeSTRef (position rotor) plus1
	when (plus1 == 'A') $ maybe (return ()) advance (nextRotor rotor)

newRotor (RotorMapping mapping) init next = do
	pos <- newSTRef init
	return (Rotor mapping pos next)

newRotors (map1,map2,map3) (init1,init2,init3) = do
	rot1 <- newRotor map1 init1 Nothing
	rot2 <- newRotor map2 init2 (Just rot1)
	rot3 <- newRotor map3 init3 (Just rot2)
	return (rot1, rot2, rot3)

look ls x = fromJust (lookup x ls)

rotorFunction rotor = do

            
Acme/Cipher.hs

rotorFunction rotor = do
	pos <- readSTRef (position rotor)
	return (look (mapping rotor) . (`subtractLetters` pos))

reverseRotorFunction rotor = do
	pos <- readSTRef (position rotor)
	return ((`addLetters` pos) . look (map swap (mapping rotor)))

randomLetter stdgen = randomR ('A','Z') stdgen

newtype Plugboard = Plugboard [(Char, Char)]


            
Acme/Cipher.hs

newtype RotorMapping = RotorMapping [(Char, Char)]

encodeEnigma (Plugboard plugboard, Reflector reflector0, mappings) (init1,init2,init3) text = do
	let reflector = reflector0 ++ map swap reflector0
	-- Create the rotors
	(rotor1,rotor2,rotor3) <- newRotors mappings (init1,init2,init3)
	-- Translate the plaintext
	mapM (\letter -> do
			f1 <- rotorFunction rotor1
			f2 <- rotorFunction rotor2
			f3 <- rotorFunction rotor3
			f4 <- reverseRotorFunction rotor1
			f5 <- reverseRotorFunction rotor2

            
Acme/Cipher.hs
			f5 <- reverseRotorFunction rotor2
			f6 <- reverseRotorFunction rotor3
			advance rotor3
			return $ look (map swap plugboard) $ f6 $ f5 $ f4 $ look reflector $ f1 $ f2 $ f3 $ look plugboard letter)
		text

enigma stdgen = Cipher (\key plaintext -> runST $ do
	-- Choose an initial rotor position
	(init1, stdgen) <- return (randomLetter stdgen)

            
Acme/Cipher.hs
	return (init1 : init2 : init3 : cipher))
	(\key (init1 : init2 : init3 : cipher) -> runST $ encodeEnigma key (init1,init2,init3) cipher)

rot13 = map (\x -> (x, addLetters x 'M')) ['A'..'N']

test = do
	ls <- shuffleM ['A'..'Z']
	let k = zip ['A'..] ls
	let key = (Plugboard k, Reflector rot13, (RotorMapping k, RotorMapping k, RotorMapping k))

            
ADPfusion-0.5.2.2
1 matches
ADP/Fusion/Core/Multi.hs
import           Data.Vector.Fusion.Stream.Monadic
import           Data.Strict.Tuple
import           Data.Proxy
import           Prelude hiding (map)

import           Data.PrimitiveArray hiding (map)

import           ADP.Fusion.Core.Classes
import           ADP.Fusion.Core.TyLvlIx