Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@michaelt
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelt/7ef6ec1824fb638be203 to your computer and use it in GitHub Desktop.
Save michaelt/7ef6ec1824fb638be203 to your computer and use it in GitHub Desktop.
more tolerant 'do'
{-#LANGUAGE RebindableSyntax, RecordWildCards, CPP, OverloadedStrings #-}
import Data.Monoid
import Prelude
import Control.Monad
import Data.String
import Text.Blaze.Html5 as H
import Text.Blaze.Html5.Attributes as A
import qualified Text.Blaze as B
data Person = Person {name :: String, age :: Int}
greet Person{..} = do
let (>>) = (<>)
"Your name is "
name
" and your age is "
show age
greet2 Person{..} = do {"Your name is "; name; " and your age is "; show age}
where (>>) = (<>)
#define monoid let (>>) = (<>) -- yeck
greet3 Person{..} = do monoid
"your name is "
name
" and your age is "
show age
-- here the point would be to dispense with the Monad instance
-- everyone whines about:
#define blaze let (>>) = (<>)
numbers n = do blaze
docTypeHtml $ do
H.head $ do
H.title "Natural numbers"
body $ do
p "A list of natural numbers:"
ul $ foldMap (li . toHtml) [1 .. n]
#define infix(x) let (>>) = (x)
aa n = do infix(+)
13
n
3 * n
foldr (*) 1 $ [1..n] ++ [5..6]
bb f g x = do infix($)
f
g
x
mklist = do infix(:)
sum [1..20]
product [2..5]
foldr (+) 0 [2..4]
[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment