Haskell Monads

class Monad m where

return :: a -> m a

(>>=) :: m a -> (a -> m b) -> m b

(>>) :: m a -> m b -> m b
x >> y = x >>= \_ -> y
fail :: String -> m a
fail msg = error msg
instance Monad Maybe where
return x = Just x
Nothing >>= f = Nothing
Just x >>= f = f x
fail _ = Nothing
  1. Identity Monad —
type I a = aunitI a = a 
a ‘bindI‘ k = k a
showI a = showval a
data E a = Success a | Error StringunitE a = Success a 
errorE s = Error s
(Success a) ‘bindE‘ k = k a
(Error s) ‘bindE‘ k = Error s
showE (Success a) = “Success: “ ++ showval a
showE (Error s) = “Error: “ ++ s




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to create a Greetings App Using Flutter and deploy to play store.

SFMC Account User Audit: Check Roles and Permissions via API

Organizing Projects Into a MonoRepo with Gradle Build Management

Load csv file from S3 to DynamoDB

Engineering for All: Single Responsibility

Arduino alarming system

Immutability of String in Java.

Plug V0.3.5 — Integrating DAB’s Canister Registry 📜 UI Polishing 🔀 and extended NFT Support 🎨

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Priyanka Mondal

Priyanka Mondal

More from Medium

InvArch and their concern for protecting intellectual property

Portraits of Spencer Lin

The beatiful mess effect

SHARKZ: The Voyage of Meta-Ocean