Skip to content

Instantly share code, notes, and snippets.

@lrlna
Created July 30, 2015 20:34
Show Gist options
  • Save lrlna/55dc6016ede656139d55 to your computer and use it in GitHub Desktop.
Save lrlna/55dc6016ede656139d55 to your computer and use it in GitHub Desktop.
intro to monads
# define a construct
data Maybe a = Just a | Nothing

#define martist
martist :: Maybe String
martist = Just "Varen"

#define mtrack
mtrack :: Maybe String
mtrack = Just "TrackName"

case martist of 
    Nothing -> 
    Just art -> case mtrack of 
      Just track ->

using monads

# type signatures/definitions
Class Monad m where
    return :: a -> m a
    (>>=) :: m a -> (a -> m b) -> m b
# can use do notation in function to iterate through
# implementation
Instance Monad Maybe wehre
    return a = Just a

# get called in order of statement; if Just a -- Just a statement
Just a >>= fn = fn a
Nothing >>= fn = Nothing 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment