Skip to content

Instantly share code, notes, and snippets.

@EvaGL
Created April 24, 2014 19:28
Show Gist options
  • Save EvaGL/11266573 to your computer and use it in GitHub Desktop.
Save EvaGL/11266573 to your computer and use it in GitHub Desktop.
Haskell
import Control.Monad
import Control.Applicative
replicateDo :: Int -> [b] -> [b]
replicateDo k xs = do
x <- xs
y <- replicate k x
return y
desintegrateDo :: Int -> [(Int, Int)]
desintegrateDo x = do
y <- [1..x]
True <- return (x `mod` y == 0 && y * y <= x)
return (y, x `div` y)
absNeighbors :: Num a => [a] -> [a]
absNeighbors xs = do
(i, x) <- zip [1..] xs
(j, y) <- zip [0..] xs
True <- return (i == j)
return $ abs (x - y)
-- Monad as Applicative
---- pure = return
---- (<*>) f x = do {f' <- f; x <- x'; return (f' x')}
-- (>=>) f g x = join $ fmap g (f x)
--
-- return >=> k == k
-- k >=> return == k
-- (u >=> v) >=> w == u >=> (v >=> w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment