Guest User

Increased `lexp` precedence: Examples (Original)

a guest
Mar 14th, 2016
20
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. === (Correct) Examples ===
  2.  
  3. Examples are in the form:
  4.  
  5. {{{#!hs
  6. implicitParenthesis -- New syntax
  7.  
  8. explicitParenthesis -- Old syntax
  9. }}}
  10.  
  11. Call {{{idM :: Monad m => m a -> m a}}} as {{{idM :: IO String -> IO String}}}.
  12.  
  13. {{{#!hs
  14. idM do
  15. putStrLn "What's my name?"
  16. getLine
  17.  
  18. idM (do { putStrLn "What's my name?"; getLine; })
  19. }}}
  20.  
  21. Create function {{{whatsMyName :: Maybe String -> String}}}.
  22.  
  23. {{{#!hs
  24. whatsMyName x = id case x of
  25. Just name = "My name is " ++ name
  26. Nothing = "What's my name?"
  27.  
  28. whatsMyName x = id (case x of { Just name = "My name is " ++ name; Nothing = "What's my name?"; })
  29. }}}
  30.  
  31. Another example using {{{let}}} and {{{if-then-else}}}.
  32.  
  33. {{{#!hs
  34. main = putStrLn
  35. (++)
  36. "I've been tryna work it out... The square root of 69 is 8 something, right? "
  37. let
  38. eight_something = 8.306623862918075
  39. in if sqrt 69 == eight_something
  40. then "Yeah"
  41. else "Oh na na"
  42.  
  43. main = putStrLn ((++) "I've been tryna work it out... The square root of 69 is 8 something, right? " (let eight_something = 8.306623862918075 in (if sqrt 69 == eight_something then "Yeah" else "Oh na na"))
  44. }}}
  45.  
  46. === Incorrect examples ===
  47.  
  48. {{{#!hs
  49. f do
  50. putStrLn "This won't work..."
  51. True
  52.  
  53. f (do { putStrLn "This won't work..."; True; })
  54. }}}
  55.  
  56. {{{#!hs
  57. f
  58. do
  59. putStrLn "This won't work..."
  60. True -- Indented by extra space
  61.  
  62. f (do { putStrLn "This won't work..."; True; })
  63. }}}
RAW Paste Data