fork download
  1. main = do
  2. void initGUI -- allocates some resources and prepares GTK+ for work, also parses command line arguments
  3. window <- windowNew -- :: Window
  4. set window [ windowTitle := "Calculator", windowResizable := False, windowDefaultWidth := 230, windowDefaultHeight := 250 ]
  5.  
  6. display <- entryNew -- Entry - a single line text entry widget
  7. set display [ entryEditable := False, entryXalign := 1 , entryText := "0" ]
  8.  
  9. grid <- gridNew
  10. gridSetRowHomogeneous grid True
  11. let attach x y w h item = gridAttach grid item x y w h
  12. attach 0 0 5 1 display
  13. mkBtn "MC" display >>= attach 0 1 1 1
  14. mkBtn "MR" display >>= attach 1 1 1 1
  15. mkBtn "MS" display >>= attach 2 1 1 1
  16. mkBtn "M+" display >>= attach 3 1 1 1
  17. mkBtn "M-" display >>= attach 4 1 1 1
  18. mkBtn "âĘŘ" display >>= attach 0 2 1 1
  19. mkBtn "CE" display >>= attach 1 2 1 1
  20. mkBtn "C" display >>= attach 2 2 1 1
  21. mkBtn "Âś" display >>= attach 3 2 1 1
  22. mkBtn "âĹŽ" display >>= attach 4 2 1 1
  23. mkBtn "7" display >>= attach 0 3 1 1
  24. mkBtn "8" display >>= attach 1 3 1 1
  25. mkBtn "9" display >>= attach 2 3 1 1
  26. mkBtn "Ãů" display >>= attach 3 3 1 1
  27. mkBtn "%" display >>= attach 4 3 1 1
  28. mkBtn "4" display >>= attach 0 4 1 1
  29. mkBtn "5" display >>= attach 1 4 1 1
  30. mkBtn "6" display >>= attach 2 4 1 1
  31. mkBtn "*" display >>= attach 3 4 1 1
  32. mkBtn "1/x" display >>= attach 4 4 1 1
  33. mkBtn "1" display >>= attach 0 5 1 1
  34. mkBtn "2" display >>= attach 1 5 1 1
  35. mkBtn "3" display >>= attach 2 5 1 1
  36. mkBtn "âĂŞ" display >>= attach 3 5 1 1
  37. mkBtn "=" display >>= attach 4 5 1 2
  38. mkBtn "0" display >>= attach 0 6 2 1
  39. mkBtn "." display >>= attach 2 6 1 1
  40. mkBtn "+" display >>= attach 3 6 1 1
  41. containerAdd window grid
  42.  
  43. widgetShowAll window
  44. mainGUI -- main loop
  45.  
  46. btnOnActivated :: Entry -> String -> IO ()
  47. btnOnActivated display label = do
  48. text <- get display entryText
  49. case label of
  50. "âĹŽ" -> set display [ entryText := show (sqrt (read text)) ]
  51. otherwise -> set display [ entryText := text++label ]
  52.  
  53. mkBtn :: String -> Entry -> IO Button
  54. mkBtn label display= do
  55. btn <- buttonNew
  56. set btn [ buttonLabel := label ]
  57. on btn buttonActivated (btnOnActivated display label)
  58. return btn
  59.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:47:32: error:
    parse error on input ‘=’
    Perhaps you need a 'let' in a 'do' block?
    e.g. 'let x = 5' instead of 'x = 5'
stdout
Standard output is empty