CARVIEW |
Select Language
HTTP/2 200
date: Sun, 12 Oct 2025 04:14:48 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=f062d29f46efa50d1717f96d43ddd36984ed4e7b18bf1c21f566e35c6c3e3f40a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%221FX-h7f4_z1Zuts4KO7kewdTRVZljakU%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d3c5c158b1dfa6-BLR
“Maybe a” emulation: monadic properties - Pastebin.com
SHARE
TWEET

“Maybe a” emulation: monadic properties
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- "Maybe a" emulation: monadic properties
- data OptionType a
- = Empty
- | NonEmpty a
- deriving (Show, Eq)
- instance Functor OptionType where
- fmap _ Empty = Empty
- fmap f (NonEmpty a) = NonEmpty $ f a
- instance Applicative OptionType where
- pure = NonEmpty
- (<*>) (NonEmpty a) (NonEmpty b) = NonEmpty $ a b
- instance Monad OptionType where
- return = NonEmpty
- -- the 'bind' operator is the >>= thingy :-)
- (>>=) Empty f = Empty
- (>>=) (NonEmpty a) f = f a
- increment :: Int -> OptionType Int
- increment x = NonEmpty (x + 1)
- feedingEmptyOptionalValue :: OptionType Int
- feedingEmptyOptionalValue = Empty >>= increment
- singleFeeding :: OptionType Int
- singleFeeding = NonEmpty 7 >>= increment
- doubleFeeding :: OptionType Int
- doubleFeeding = NonEmpty 7 >>= increment >>= increment
- fuckUpPipeline :: OptionType Int
- fuckUpPipeline = NonEmpty 7 >>= increment >>= (\_ -> Empty) >>= increment
- outputText =
- [ "1. An empty optional value: "
- , show (Empty :: OptionType Int)
- , "2. An non-empty optional value: "
- , show (NonEmpty 7)
- , "3. Feeding an empty optional value to the increment function:"
- , "Empty >>= increment → "
- , show feedingEmptyOptionalValue
- , "4. Feeding an non-empty optional value to the increment function:"
- , "NonEmpty 7 >>= increment → "
- , show singleFeeding
- , "5. A two-section pipeline with the increment function:"
- , "NonEmpty 7 >>= increment >>= increment → "
- , show doubleFeeding
- , "6. A three-section pipeline showcasing failure propagation:"
- , "NonEmpty 7 >>= increment >>= (\\_ -> Empty) >>= increment → "
- , show fuckUpPipeline
- , "7. The first monadic law: return a >>= h ≡ h a:"
- , "(return 7 >>= increment) == increment 7 →"
- , show $ (return 7 >>= increment) == increment 7
- , "8. The second monadic law: m >>= return ≡ m:"
- , "(NonEmpty 7 >>= return) == NonEmpty 7 →"
- , show $ (NonEmpty 7 >>= return) == NonEmpty 7
- , "9. The third monadic law: (m >>= g) >>= h ≡ m >>= (\\x -> g x >>= h):"
- , "((NonEmpty 7 >>= (\\_ -> Empty)) >>= increment) == (NonEmpty 7 >>= (\\x -> (\\_ -> Empty) x >>= increment)) →"
- , show $ ((NonEmpty 7 >>= (\_ -> Empty)) >>= increment) == (NonEmpty 7 >>= (\x -> (\_ -> Empty) x >>= increment))
- ]
- main :: IO ()
- main = mapM_ putStrLn outputText
- -- 1. An empty optional value:
- -- Empty
- -- 2. An non-empty optional value:
- -- NonEmpty 7
- -- 3. Feeding an empty optional value to the increment function:
- -- Empty >>= increment →
- -- Empty
- -- 4. Feeding an non-empty optional value to the increment function:
- -- NonEmpty 7 >>= increment →
- -- NonEmpty 8
- -- 5. A two-section pipeline with the increment function:
- -- NonEmpty 7 >>= increment >>= increment →
- -- NonEmpty 9
- -- 6. A three-section pipeline showcasing failure propagation:
- -- NonEmpty 7 >>= increment >>= (\_ -> Empty) >>= increment →
- -- Empty
- -- 7. The first monadic law: return a >>= h ≡ h a:
- -- (return 7 >>= increment) == increment 7 →
- -- True
- -- 8. The second monadic law: m >>= return ≡ m:
- -- (NonEmpty 7 >>= return) == NonEmpty 7 →
- -- True
- -- 9. The third monadic law: (m >>= g) >>= h ≡ m >>= (\x -> g x >>= h):
- -- ((NonEmpty 7 >>= (\_ -> Empty)) >>= increment) == (NonEmpty 7 >>= (\x -> (\_ -> Empty) x >>= increment)) →
- -- True
Advertisement
Add Comment
Please, Sign In to add comment
-
✅⭐ Make huge profits on trading ⭐⭐ S
JavaScript | 10 sec ago | 0.25 KB
-
📌 Instant BTC Profit Method ✅ Working
JavaScript | 14 sec ago | 0.24 KB
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 19 sec ago | 0.25 KB
-
📝 Crypto Swap Glitch ✅ Working
JavaScript | 24 sec ago | 0.24 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ G
JavaScript | 28 sec ago | 0.25 KB
-
📌 ChangeNOW Exploit
JavaScript | 34 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ X
JavaScript | 37 sec ago | 0.25 KB
-
⭐ Free Crypto Method ⭐
JavaScript | 44 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand