Simple Go, Complex Haskell
An idiot admires complexity, a genius admires simplicity. package main import "fmt" func gcd(a, b int) int { for b != 0 { a, b = b, a%b } return a } func main() { fmt.Println(gcd(69, 42)) } import Control.Monad.State import System.IO type GCDState = (Int, Int) step :: State GCDState (Maybe Int) step = do (a, b) <- get if b == 0 then return (Just a) else return (b, (a `mod` b)) >> return Nothing gcdRecursive :: State GCDState Int gcdRecursive = do result <- step case result of Just v -> return v Nothing -> gcdRecursive computeGCD :: Int -> Int -> Int a b = evalState gcdRecursive (a, b) main :: IO () main = do hSetBuffering stdout NoBuffering putStrLn $ show (computeGCD 69 42)
The meme contrasts a short, straightforward Go implementation of the greatest common divisor with an elaborate Haskell version using monadic state. The joke is that the supposedly genius approach admires complexity, while the idiot's approach is simple and readable. EN: The meme contrasts a short, straightforward Go implementation of the greatest common divisor with an elaborate Haskell version using monadic state. The joke is that the supposedly genius approach admires complexity, while the idiot's approach is simple and readable.
Go logo / логотип GoHaskell logo / логотип Haskellcode editor panel / панель редактора кодаGo source code / исходный код на GoHaskell source code / исходный код на Haskellcomputer programming / программированиеtext post / текстовый постblack background / чёрный фонpurple avatar / фиолетовый аватарgreatest common divisor function / функция наибольшего общего делителяnumber 69 / число 69number 42 / число 42
- @ithueti / 14682 2024-11-29
- Type
- image
- Size
- 800×636 · 63.2 KiB
- Mood
- sarcastic, absurd
- Language
- en
- Added