-
-
Save EvaGL/11266573 to your computer and use it in GitHub Desktop.
Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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