karlangadas

haskell

Aug 25th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Graphics.UI.Gtk
  2.  
  3.  
  4. main :: IO ()
  5. main = do
  6.    initGUI
  7.    window <- windowNew
  8.    set window [windowTitle:="Operaciones sencillas", containerBorderWidth := 20,
  9.                windowDefaultWidth:=150, windowDefaultHeight:=100]
  10.    table <- tableNew 4 2 True
  11.    containerAdd window table
  12.    label1 <-labelNew (Just "Ingrese un entero positivo:")
  13.    tableAttachDefaults table dataText 0 1 1 2
  14.    button1 <- buttonNewWithLabel "Calcula el factorial"
  15.    tableAttachDefaults table button1 1 2 1 2
  16.    label2 <- labelNew(Just"")
  17.    tableAttachDefaults table button2 0 2 3 4
  18.    onClicked button2 mainQuit
  19.    onClicked button1 (sol dataText label2)
  20.    onDestroy window mainQuit
  21.    widgetShowAll window
  22.    mainGUI
  23.    
  24. sol :: Entry -> Label -> IO ()
  25. sol dT l2 = do
  26.    txt <- entryGetText dT
  27.    labelSetText l2 ("El factorial de "++ txt ++ " es: " ++ (fact txt))
  28.  
  29. fact :: String -> String
  30. fact txt = show (product [1.. (read txt :: Int)])
Advertisement
Add Comment
Please, Sign In to add comment