code_junkie

What type of scope does Haskell use?

Nov 12th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. let x = 10
  2.  
  3. let square x = x*x
  4.  
  5. import Data.IORef
  6.  
  7. main :: IO ()
  8. main = do x <- newIORef 0 -- write 0 into x
  9. readIORef x >>= print -- x contains 0
  10. let y = x
  11. readIORef y >>= print -- y contains 0
  12. writeIORef x 42 -- write 42 into x
  13. readIORef y >>= print -- y contains 42
  14.  
  15. x = 10
  16.  
  17. square x = x * x
  18.  
  19. square = x -> x * x
  20.  
  21. foo x y = x * y
  22. bar z = foo z z
  23.  
  24. y = x
  25.  
  26. type Function = Double -> Double
  27.  
  28. evens = 0 : map (+1) odds
  29. odds = map : (+1) evens
  30.  
  31. let x = 2 * n
  32. x = x + 1 -- watch out!
  33.  
  34. import Data.IORef
  35.  
  36. main :: IO ()
  37. main = do x <- newIORef 0 -- write 0 into x
  38. readIORef x >>= print -- x contains 0
  39. let y = x
  40. readIORef y >>= print -- y contains 0
  41. writeIORef x 42 -- write 42 into x
  42. readIORef y >>= print -- y contains 42
Add Comment
Please, Sign In to add comment