diff options
| author | Raymond Hogenson <rhogenson@posteo.net> | 2018-05-17 09:42:44 -0800 |
|---|---|---|
| committer | Raymond Hogenson <rhogenson@posteo.net> | 2018-05-17 09:43:54 -0800 |
| commit | 78001436a52a4cc9b5e22bca489fb8ed09a72376 (patch) | |
| tree | 0c88a126b1169000d6312d21792b10e8724fab6f /main.hs | |
| download | hsc-78001436a52a4cc9b5e22bca489fb8ed09a72376.tar.zst | |
Write a calculator
It's pretty nice. It works for what I want. I don't think I have any
complaints about its functionality. I'll add new functions as I need
them. Haskell is actually really easy to program in. I wonder actually
if this would have been easier in Python. I think no.
Diffstat (limited to 'main.hs')
| -rw-r--r-- | main.hs | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -0,0 +1,34 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Graphics.UI.Gtk +import qualified Control.Monad.IO.Class as Cl +import qualified RealCalc + +main :: IO () +main = do _ <- initGUI + w <- windowNew + windowSetKeepAbove w True + set w [ windowDecorated := False, windowTypeHint := WindowTypeHintDock, windowResizable := False ] + grid <- gridNew + input <- entryNew + output <- labelNew (Nothing :: Maybe String) + gridAttach grid input 0 0 1 1 + gridAttach grid output 0 1 1 1 + containerAdd w grid + _ <- w `on` deleteEvent $ do + Cl.liftIO mainQuit + return False + _ <- input `on` keyReleaseEvent $ do + k <- eventKeyName + let quit = Cl.liftIO mainQuit + case k of + "Escape" -> quit + "Return" -> quit + _ -> return () + s <- Cl.liftIO $ entryGetText input + case RealCalc.calculate s of + Nothing -> return () + Just r -> Cl.liftIO $ labelSetText output r + return False + widgetShowAll w + mainGUI |
