From 19ce70b34ada5919e55e5d8bb3a0167d0062215a Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Mon, 11 Mar 2024 11:39:53 -0500 Subject: [PATCH 01/16] Init stack project --- haskell/gtk-gui/.gitignore | 2 + haskell/gtk-gui/README.md | 1 + haskell/gtk-gui/Setup.hs | 2 + haskell/gtk-gui/app/Main.hs | 6 +++ haskell/gtk-gui/gtk-gui.cabal | 52 +++++++++++++++++++++++++ haskell/gtk-gui/package.yaml | 59 +++++++++++++++++++++++++++++ haskell/gtk-gui/src/Lib.hs | 6 +++ haskell/gtk-gui/stack.yaml | 67 +++++++++++++++++++++++++++++++++ haskell/gtk-gui/stack.yaml.lock | 13 +++++++ 9 files changed, 208 insertions(+) create mode 100644 haskell/gtk-gui/.gitignore create mode 100644 haskell/gtk-gui/README.md create mode 100644 haskell/gtk-gui/Setup.hs create mode 100644 haskell/gtk-gui/app/Main.hs create mode 100644 haskell/gtk-gui/gtk-gui.cabal create mode 100644 haskell/gtk-gui/package.yaml create mode 100644 haskell/gtk-gui/src/Lib.hs create mode 100644 haskell/gtk-gui/stack.yaml create mode 100644 haskell/gtk-gui/stack.yaml.lock diff --git a/haskell/gtk-gui/.gitignore b/haskell/gtk-gui/.gitignore new file mode 100644 index 0000000..c368d45 --- /dev/null +++ b/haskell/gtk-gui/.gitignore @@ -0,0 +1,2 @@ +.stack-work/ +*~ \ No newline at end of file diff --git a/haskell/gtk-gui/README.md b/haskell/gtk-gui/README.md new file mode 100644 index 0000000..05b6af2 --- /dev/null +++ b/haskell/gtk-gui/README.md @@ -0,0 +1 @@ +# gtk-gui diff --git a/haskell/gtk-gui/Setup.hs b/haskell/gtk-gui/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/haskell/gtk-gui/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/haskell/gtk-gui/app/Main.hs b/haskell/gtk-gui/app/Main.hs new file mode 100644 index 0000000..4c6b30f --- /dev/null +++ b/haskell/gtk-gui/app/Main.hs @@ -0,0 +1,6 @@ +module Main (main) where + +import Lib + +main :: IO () +main = someFunc diff --git a/haskell/gtk-gui/gtk-gui.cabal b/haskell/gtk-gui/gtk-gui.cabal new file mode 100644 index 0000000..a3b29cf --- /dev/null +++ b/haskell/gtk-gui/gtk-gui.cabal @@ -0,0 +1,52 @@ +cabal-version: 2.2 + +-- This file has been generated from package.yaml by hpack version 0.36.0. +-- +-- see: https://github.com/sol/hpack + +name: gtk-gui +version: 0.1.0.0 +description: Please see the README on GitHub at +homepage: https://github.com/githubuser/gtk-gui#readme +bug-reports: https://github.com/githubuser/gtk-gui/issues +author: Author name here +maintainer: example@example.com +copyright: 2024 Author name here +license: BSD-3-Clause +license-file: LICENSE +build-type: Simple +extra-source-files: + README.md + CHANGELOG.md + +source-repository head + type: git + location: https://github.com/githubuser/gtk-gui + +library + exposed-modules: + Lib + other-modules: + Paths_gtk_gui + autogen-modules: + Paths_gtk_gui + hs-source-dirs: + src + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints + build-depends: + base >=4.7 && <5 + default-language: Haskell2010 + +executable gtk-gui-exe + main-is: Main.hs + other-modules: + Paths_gtk_gui + autogen-modules: + Paths_gtk_gui + hs-source-dirs: + app + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 && <5 + , gtk-gui + default-language: Haskell2010 diff --git a/haskell/gtk-gui/package.yaml b/haskell/gtk-gui/package.yaml new file mode 100644 index 0000000..eda2188 --- /dev/null +++ b/haskell/gtk-gui/package.yaml @@ -0,0 +1,59 @@ +name: gtk-gui +version: 0.1.0.0 +github: "githubuser/gtk-gui" +license: BSD-3-Clause +author: "Author name here" +maintainer: "example@example.com" +copyright: "2024 Author name here" + +extra-source-files: +- README.md +- CHANGELOG.md + +# Metadata used when publishing your package +# synopsis: Short description of your package +# category: Web + +# To avoid duplicated efforts in documentation and dealing with the +# complications of embedding Haddock markup inside cabal files, it is +# common to point users to the README.md file. +description: Please see the README on GitHub at + +dependencies: +- base >= 4.7 && < 5 + +ghc-options: +- -Wall +- -Wcompat +- -Widentities +- -Wincomplete-record-updates +- -Wincomplete-uni-patterns +- -Wmissing-export-lists +- -Wmissing-home-modules +- -Wpartial-fields +- -Wredundant-constraints + +library: + source-dirs: src + +executables: + gtk-gui-exe: + main: Main.hs + source-dirs: app + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - gtk-gui + +tests: + gtk-gui-test: + main: Spec.hs + source-dirs: test + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - gtk-gui diff --git a/haskell/gtk-gui/src/Lib.hs b/haskell/gtk-gui/src/Lib.hs new file mode 100644 index 0000000..d36ff27 --- /dev/null +++ b/haskell/gtk-gui/src/Lib.hs @@ -0,0 +1,6 @@ +module Lib + ( someFunc + ) where + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/haskell/gtk-gui/stack.yaml b/haskell/gtk-gui/stack.yaml new file mode 100644 index 0000000..baad085 --- /dev/null +++ b/haskell/gtk-gui/stack.yaml @@ -0,0 +1,67 @@ +# This file was automatically generated by 'stack init' +# +# Some commonly used options have been documented as comments in this file. +# For advanced use and comprehensive documentation of the format, please see: +# https://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Resolver to choose a 'specific' stackage snapshot or a compiler version. +# A snapshot resolver dictates the compiler version and the set of packages +# to be used for project dependencies. For example: +# +# resolver: lts-21.13 +# resolver: nightly-2023-09-24 +# resolver: ghc-9.6.2 +# +# The location of a snapshot can be provided as a file or url. Stack assumes +# a snapshot provided as a file might change, whereas a url resource does not. +# +# resolver: ./custom-snapshot.yaml +# resolver: https://example.com/snapshots/2023-01-01.yaml +resolver: + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/11.yaml + +# User packages to be built. +# Various formats can be used as shown in the example below. +# +# packages: +# - some-directory +# - https://example.com/foo/bar/baz-0.0.2.tar.gz +# subdirs: +# - auto-update +# - wai +packages: +- . +# Dependency packages to be pulled from upstream that are not in the resolver. +# These entries can reference officially published versions as well as +# forks / in-progress versions pinned to a git hash. For example: +# +# extra-deps: +# - acme-missiles-0.3 +# - git: https://github.com/commercialhaskell/stack.git +# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# +# extra-deps: [] + +# Override default flag values for local packages and extra-deps +# flags: {} + +# Extra package databases containing global packages +# extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true +# +# Require a specific version of Stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: ">=2.13" +# +# Override the architecture used by Stack, especially useful on Windows +# arch: i386 +# arch: x86_64 +# +# Extra directories used by Stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] +# +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor diff --git a/haskell/gtk-gui/stack.yaml.lock b/haskell/gtk-gui/stack.yaml.lock new file mode 100644 index 0000000..433458b --- /dev/null +++ b/haskell/gtk-gui/stack.yaml.lock @@ -0,0 +1,13 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + sha256: 2fdd7d3e54540062ef75ca0a73ca3a804c527dbf8a4cadafabf340e66ac4af40 + size: 712469 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/11.yaml + original: + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/11.yaml From 9312ed17a362e3f81686fcfc602cedd08538a072 Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Mon, 11 Mar 2024 12:00:28 -0500 Subject: [PATCH 02/16] Calculator code --- haskell/gtk-gui/app/Main.hs | 2 +- haskell/gtk-gui/gtk-gui.cabal | 19 ++- haskell/gtk-gui/src/Lib.hs | 216 +++++++++++++++++++++++++++++++++- 3 files changed, 231 insertions(+), 6 deletions(-) diff --git a/haskell/gtk-gui/app/Main.hs b/haskell/gtk-gui/app/Main.hs index 4c6b30f..da8b344 100644 --- a/haskell/gtk-gui/app/Main.hs +++ b/haskell/gtk-gui/app/Main.hs @@ -3,4 +3,4 @@ module Main (main) where import Lib main :: IO () -main = someFunc +main = renderCalculator diff --git a/haskell/gtk-gui/gtk-gui.cabal b/haskell/gtk-gui/gtk-gui.cabal index a3b29cf..9176b0e 100644 --- a/haskell/gtk-gui/gtk-gui.cabal +++ b/haskell/gtk-gui/gtk-gui.cabal @@ -13,7 +13,6 @@ author: Author name here maintainer: example@example.com copyright: 2024 Author name here license: BSD-3-Clause -license-file: LICENSE build-type: Simple extra-source-files: README.md @@ -34,7 +33,8 @@ library src ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints build-depends: - base >=4.7 && <5 + base >=4.7 && <5, + gtk3 default-language: Haskell2010 executable gtk-gui-exe @@ -50,3 +50,18 @@ executable gtk-gui-exe base >=4.7 && <5 , gtk-gui default-language: Haskell2010 + +test-suite gtk-gui-test + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + Paths_gtk_gui + autogen-modules: + Paths_gtk_gui + hs-source-dirs: + test + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 && <5 + , gtk-gui + default-language: Haskell2010 diff --git a/haskell/gtk-gui/src/Lib.hs b/haskell/gtk-gui/src/Lib.hs index d36ff27..573083f 100644 --- a/haskell/gtk-gui/src/Lib.hs +++ b/haskell/gtk-gui/src/Lib.hs @@ -1,6 +1,216 @@ module Lib - ( someFunc + ( renderCalculator ) where -someFunc :: IO () -someFunc = putStrLn "someFunc" +import Control.Monad +import Control.Monad.IO.Class +import Data.IORef +import Graphics.UI.Gtk hiding (Action, backspace) + +renderCalculator :: IO () +renderCalculator = do + st <- newIORef (Value "" Nothing) + void initGUI + window <- renderWindow + display <- renderDisplay + grid <- gridNew + gridSetRowHomogeneous grid True + let attach x y w h item = gridAttach grid item x y w h + mkBtn = mkButton st display + attach 0 0 5 1 display + mkBtn "MC" id >>= attach 0 1 1 1 + mkBtn "MR" id >>= attach 1 1 1 1 + mkBtn "MS" id >>= attach 2 1 1 1 + mkBtn "M+" id >>= attach 3 1 1 1 + mkBtn "M–" id >>= attach 4 1 1 1 + mkBtn "←" backspace >>= attach 0 2 1 1 + mkBtn "CE" clearEntry >>= attach 1 2 1 1 + mkBtn "C" clearAll >>= attach 2 2 1 1 + mkBtn "±" id >>= attach 3 2 1 1 + mkBtn "√" id >>= attach 4 2 1 1 + mkBtn "7" (enterDigit '7') >>= attach 0 3 1 1 + mkBtn "8" (enterDigit '8') >>= attach 1 3 1 1 + mkBtn "9" (enterDigit '9') >>= attach 2 3 1 1 + mkBtn "÷" (operator Division) >>= attach 3 3 1 1 + mkBtn "%" id >>= attach 4 3 1 1 + mkBtn "4" (enterDigit '4') >>= attach 0 4 1 1 + mkBtn "5" (enterDigit '5') >>= attach 1 4 1 1 + mkBtn "6" (enterDigit '6') >>= attach 2 4 1 1 + mkBtn "*" (operator Multiplication) >>= attach 3 4 1 1 + mkBtn "1/x" id >>= attach 4 4 1 1 + mkBtn "1" (enterDigit '1') >>= attach 0 5 1 1 + mkBtn "2" (enterDigit '2') >>= attach 1 5 1 1 + mkBtn "3" (enterDigit '3') >>= attach 2 5 1 1 + mkBtn "–" (operator Subtraction) >>= attach 3 5 1 1 + mkBtn "=" equals >>= attach 4 5 1 2 + mkBtn "0" (enterDigit '0') >>= attach 0 6 2 1 + mkBtn "." enterDot >>= attach 2 6 1 1 + mkBtn "+" (operator Addition) >>= attach 3 6 1 1 + containerAdd window grid + window `on` deleteEvent $ do + liftIO mainQuit + return False + widgetShowAll window + mainGUI + +---------------------------------------------------------------------------- +-- Calculator's state + +-- | 'Value' holds textual representation of first argument reversed and +-- 'Action' to apply to it, which see. +data Value = Value String (Maybe Action) + +-- | Action to apply to first argument and textual representation of second +-- argument reversed (if relevant). +data Action + = Addition String + | Subtraction String + | Multiplication String + | Division String + +-- | Change second argument inside of 'Action'. +mapAction :: (String -> String) -> Action -> Action +mapAction f (Addition x) = Addition (f x) +mapAction f (Subtraction x) = Subtraction (f x) +mapAction f (Multiplication x) = Multiplication (f x) +mapAction f (Division x) = Division (f x) + +-- | Get second argument from 'Action'. +getSndArg :: Action -> String +getSndArg (Addition x) = x +getSndArg (Subtraction x) = x +getSndArg (Multiplication x) = x +getSndArg (Division x) = x + +-- | Render given 'Value'. +renderValue :: Value -> String +renderValue (Value x action) = + g x ++ f a ++ (if null y then "" else g y) + where + (a, y) = + case action of + Nothing -> ("", "") + Just (Addition arg) -> ("+", arg) + Just (Subtraction arg) -> ("–", arg) + Just (Multiplication arg) -> ("*", arg) + Just (Division arg) -> ("÷", arg) + f "" = "" + f l = " " ++ l ++ " " + g "" = "0" + g xs = reverse xs + +---------------------------------------------------------------------------- +-- Calculator's operations + +-- | Change state as if a dot is entered. +enterDot :: Value -> Value +enterDot (Value x action) = + let f xs = if '.' `elem` xs then xs else '.' : xs + in case action of + Nothing -> Value (f x) Nothing + Just a -> Value x (Just $ mapAction f a) + +-- | Change state as if specific char (digit) is entered. +enterDigit :: Char -> Value -> Value +enterDigit ch (Value x action) = + case action of + Nothing -> Value (ch:x) Nothing + Just a -> Value x (Just $ mapAction (ch:) a) + +-- | Change state as if last character of current argument is removed. +backspace :: Value -> Value +backspace (Value x action) = + case action of + Nothing -> Value (drop 1 x) Nothing + Just a -> Value x (Just $ mapAction (drop 1) a) + +-- | Apply given operator to current state. If some action is already fully +-- constructed, evaluate it first. +operator :: (String -> Action) -> Value -> Value +operator op value = + let (Value x action) = equals value + in Value x $ Just $ + case action of + Nothing -> op "" + Just a -> op (getSndArg a) + +-- | Change state as if current argument is removed. +clearEntry :: Value -> Value +clearEntry (Value x action) = + case action of + Nothing -> Value "" Nothing + Just a -> + if null (getSndArg a) + then Value "" Nothing + else Value x (Just $ mapAction (const "") a) + +-- | Change state returning it to the default value. +clearAll :: Value -> Value +clearAll = const (Value "" Nothing) + +-- | Evaluate current calculator's state putting result in place of first +-- argument. +equals :: Value -> Value +equals (Value x action) = + case action of + Nothing -> Value x Nothing + Just a -> + if null (getSndArg a) + then Value x action + else Value result Nothing + where + g :: String -> Double + g "" = 0 + g ('.':xs) = g ('0':'.':xs) + g xs = read (reverse xs) + x' = g x + y' = g (getSndArg a) + result = reverse . show $ + case a of + Addition _ -> x' + y' + Subtraction _ -> x' - y' + Multiplication _ -> x' * y' + Division _ -> x' / y' + +---------------------------------------------------------------------------- +-- Helpers + +-- | Create a button and attach handler to it that mutates calculator's +-- state with given function. +mkButton + :: IORef Value -- ^ 'IORef' to calculator state + -> Entry -- ^ Our display to update + -> String -- ^ Button label + -> (Value -> Value) -- ^ How this button affects calculator state + -> IO Button -- ^ Resulting button object +mkButton st display label mutateState = do + btn <- buttonNew + set btn [ buttonLabel := label ] + btn `on` buttonActivated $ do + value <- atomicModifyIORef st $ \x -> let r = mutateState x in (r, r) + updateDisplay display value + return btn + +-- | Make calculator's display show given 'Value'. +updateDisplay :: Entry -> Value -> IO () +updateDisplay display value = + set display [ entryText := renderValue value ] + +-- | Create a new window with default settings. +renderWindow :: IO Window +renderWindow = do + window <- windowNew + set window [ windowTitle := "Hello World" + , windowResizable := False + , windowDefaultWidth := 230 + , windowDefaultHeight := 150 ] + pure window + +-- | Create a new display with default settings. +renderDisplay :: IO Entry +renderDisplay = do + display <- entryNew + set display [ entryEditable := False + , entryXalign := 1 -- makes contents right-aligned + , entryText := "0" ] + pure display From f0708894cd16de69c43067915abf0a2a3cf24bb0 Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Tue, 12 Mar 2024 10:23:26 -0500 Subject: [PATCH 03/16] Update stack.yaml --- haskell/gtk-gui/stack.yaml | 62 -------------------------------------- 1 file changed, 62 deletions(-) diff --git a/haskell/gtk-gui/stack.yaml b/haskell/gtk-gui/stack.yaml index baad085..e72136c 100644 --- a/haskell/gtk-gui/stack.yaml +++ b/haskell/gtk-gui/stack.yaml @@ -1,67 +1,5 @@ -# This file was automatically generated by 'stack init' -# -# Some commonly used options have been documented as comments in this file. -# For advanced use and comprehensive documentation of the format, please see: -# https://docs.haskellstack.org/en/stable/yaml_configuration/ - -# Resolver to choose a 'specific' stackage snapshot or a compiler version. -# A snapshot resolver dictates the compiler version and the set of packages -# to be used for project dependencies. For example: -# -# resolver: lts-21.13 -# resolver: nightly-2023-09-24 -# resolver: ghc-9.6.2 -# -# The location of a snapshot can be provided as a file or url. Stack assumes -# a snapshot provided as a file might change, whereas a url resource does not. -# -# resolver: ./custom-snapshot.yaml -# resolver: https://example.com/snapshots/2023-01-01.yaml resolver: url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/11.yaml -# User packages to be built. -# Various formats can be used as shown in the example below. -# -# packages: -# - some-directory -# - https://example.com/foo/bar/baz-0.0.2.tar.gz -# subdirs: -# - auto-update -# - wai packages: - . -# Dependency packages to be pulled from upstream that are not in the resolver. -# These entries can reference officially published versions as well as -# forks / in-progress versions pinned to a git hash. For example: -# -# extra-deps: -# - acme-missiles-0.3 -# - git: https://github.com/commercialhaskell/stack.git -# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a -# -# extra-deps: [] - -# Override default flag values for local packages and extra-deps -# flags: {} - -# Extra package databases containing global packages -# extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true -# -# Require a specific version of Stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: ">=2.13" -# -# Override the architecture used by Stack, especially useful on Windows -# arch: i386 -# arch: x86_64 -# -# Extra directories used by Stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir] -# -# Allow a newer minor version of GHC than the snapshot specifies -# compiler-check: newer-minor From 3d2da33086527504d78776dc10cba90146fe33dd Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Tue, 12 Mar 2024 10:45:41 -0500 Subject: [PATCH 04/16] Update resolver --- haskell/gtk-gui/stack.yaml | 3 +-- haskell/gtk-gui/stack.yaml.lock | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/haskell/gtk-gui/stack.yaml b/haskell/gtk-gui/stack.yaml index e72136c..c7e4783 100644 --- a/haskell/gtk-gui/stack.yaml +++ b/haskell/gtk-gui/stack.yaml @@ -1,5 +1,4 @@ -resolver: - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/11.yaml +resolver: lts-21.13 packages: - . diff --git a/haskell/gtk-gui/stack.yaml.lock b/haskell/gtk-gui/stack.yaml.lock index 433458b..d968e8d 100644 --- a/haskell/gtk-gui/stack.yaml.lock +++ b/haskell/gtk-gui/stack.yaml.lock @@ -6,8 +6,7 @@ packages: [] snapshots: - completed: - sha256: 2fdd7d3e54540062ef75ca0a73ca3a804c527dbf8a4cadafabf340e66ac4af40 - size: 712469 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/11.yaml - original: - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/11.yaml + sha256: 8017c7970c2a8a9510c60cc70ac245d59e0c34eb932b91d37af09fe59855d854 + size: 640038 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/13.yaml + original: lts-21.13 From cecadce9202fdb921adc6a909cbfd99acb59c566 Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Tue, 12 Mar 2024 10:49:22 -0500 Subject: [PATCH 05/16] Remove unnecessary ghc-options --- haskell/gtk-gui/gtk-gui.cabal | 2 -- 1 file changed, 2 deletions(-) diff --git a/haskell/gtk-gui/gtk-gui.cabal b/haskell/gtk-gui/gtk-gui.cabal index 9176b0e..1026759 100644 --- a/haskell/gtk-gui/gtk-gui.cabal +++ b/haskell/gtk-gui/gtk-gui.cabal @@ -31,7 +31,6 @@ library Paths_gtk_gui hs-source-dirs: src - ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints build-depends: base >=4.7 && <5, gtk3 @@ -45,7 +44,6 @@ executable gtk-gui-exe Paths_gtk_gui hs-source-dirs: app - ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.7 && <5 , gtk-gui From 5a169bdf36a7939d43cc3d869d1bb0c441bed66d Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Tue, 12 Mar 2024 10:50:49 -0500 Subject: [PATCH 06/16] Remove test suites --- haskell/gtk-gui/gtk-gui.cabal | 15 --------------- haskell/gtk-gui/package.yaml | 22 ---------------------- 2 files changed, 37 deletions(-) diff --git a/haskell/gtk-gui/gtk-gui.cabal b/haskell/gtk-gui/gtk-gui.cabal index 1026759..1f8231e 100644 --- a/haskell/gtk-gui/gtk-gui.cabal +++ b/haskell/gtk-gui/gtk-gui.cabal @@ -48,18 +48,3 @@ executable gtk-gui-exe base >=4.7 && <5 , gtk-gui default-language: Haskell2010 - -test-suite gtk-gui-test - type: exitcode-stdio-1.0 - main-is: Spec.hs - other-modules: - Paths_gtk_gui - autogen-modules: - Paths_gtk_gui - hs-source-dirs: - test - ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N - build-depends: - base >=4.7 && <5 - , gtk-gui - default-language: Haskell2010 diff --git a/haskell/gtk-gui/package.yaml b/haskell/gtk-gui/package.yaml index eda2188..2d65e2e 100644 --- a/haskell/gtk-gui/package.yaml +++ b/haskell/gtk-gui/package.yaml @@ -22,17 +22,6 @@ description: Please see the README on GitHub at = 4.7 && < 5 -ghc-options: -- -Wall -- -Wcompat -- -Widentities -- -Wincomplete-record-updates -- -Wincomplete-uni-patterns -- -Wmissing-export-lists -- -Wmissing-home-modules -- -Wpartial-fields -- -Wredundant-constraints - library: source-dirs: src @@ -46,14 +35,3 @@ executables: - -with-rtsopts=-N dependencies: - gtk-gui - -tests: - gtk-gui-test: - main: Spec.hs - source-dirs: test - ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N - dependencies: - - gtk-gui From ee5335c7e99c8463b8965e98f9684e928a42bd3b Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Tue, 12 Mar 2024 11:08:51 -0500 Subject: [PATCH 07/16] Define boundaries gtk3 --- haskell/gtk-gui/package.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/haskell/gtk-gui/package.yaml b/haskell/gtk-gui/package.yaml index 2d65e2e..c55b874 100644 --- a/haskell/gtk-gui/package.yaml +++ b/haskell/gtk-gui/package.yaml @@ -21,6 +21,7 @@ description: Please see the README on GitHub at = 4.7 && < 5 +- gtk3 >= 0.15.8 library: source-dirs: src From 7abc29f9f6d8f368fb1de32e9211a5ffe9f2ab2c Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Tue, 12 Mar 2024 11:41:49 -0500 Subject: [PATCH 08/16] Update general information --- haskell/gtk-gui/gtk-gui.cabal | 11 ----------- haskell/gtk-gui/package.yaml | 20 ++++---------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/haskell/gtk-gui/gtk-gui.cabal b/haskell/gtk-gui/gtk-gui.cabal index 1f8231e..8449adc 100644 --- a/haskell/gtk-gui/gtk-gui.cabal +++ b/haskell/gtk-gui/gtk-gui.cabal @@ -6,17 +6,6 @@ cabal-version: 2.2 name: gtk-gui version: 0.1.0.0 -description: Please see the README on GitHub at -homepage: https://github.com/githubuser/gtk-gui#readme -bug-reports: https://github.com/githubuser/gtk-gui/issues -author: Author name here -maintainer: example@example.com -copyright: 2024 Author name here -license: BSD-3-Clause -build-type: Simple -extra-source-files: - README.md - CHANGELOG.md source-repository head type: git diff --git a/haskell/gtk-gui/package.yaml b/haskell/gtk-gui/package.yaml index c55b874..64b43fa 100644 --- a/haskell/gtk-gui/package.yaml +++ b/haskell/gtk-gui/package.yaml @@ -1,22 +1,14 @@ name: gtk-gui version: 0.1.0.0 -github: "githubuser/gtk-gui" +github: "stackbuilders/blog-code" license: BSD-3-Clause -author: "Author name here" -maintainer: "example@example.com" -copyright: "2024 Author name here" +author: "Mark Karpov" +maintainer: "jgalarza@stackbuilders.com" +copyright: "2016 Mark Karpov" extra-source-files: - README.md -- CHANGELOG.md -# Metadata used when publishing your package -# synopsis: Short description of your package -# category: Web - -# To avoid duplicated efforts in documentation and dealing with the -# complications of embedding Haddock markup inside cabal files, it is -# common to point users to the README.md file. description: Please see the README on GitHub at dependencies: @@ -30,9 +22,5 @@ executables: gtk-gui-exe: main: Main.hs source-dirs: app - ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N dependencies: - gtk-gui From 5d2a13b25ccc53bd5196adc81fcc6de98409db1b Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Wed, 13 Mar 2024 12:57:18 -0500 Subject: [PATCH 09/16] Adjust window settings --- haskell/gtk-gui/src/Lib.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/haskell/gtk-gui/src/Lib.hs b/haskell/gtk-gui/src/Lib.hs index 573083f..95c186b 100644 --- a/haskell/gtk-gui/src/Lib.hs +++ b/haskell/gtk-gui/src/Lib.hs @@ -200,10 +200,10 @@ updateDisplay display value = renderWindow :: IO Window renderWindow = do window <- windowNew - set window [ windowTitle := "Hello World" + set window [ windowTitle := "Calculator" , windowResizable := False , windowDefaultWidth := 230 - , windowDefaultHeight := 150 ] + , windowDefaultHeight := 250 ] pure window -- | Create a new display with default settings. From 6b78444629e0e9e2afe9d875389a9171cf50b277 Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Thu, 14 Mar 2024 15:51:58 -0500 Subject: [PATCH 10/16] Restric upper bounder --- haskell/gtk-gui/package.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haskell/gtk-gui/package.yaml b/haskell/gtk-gui/package.yaml index 64b43fa..c025bdb 100644 --- a/haskell/gtk-gui/package.yaml +++ b/haskell/gtk-gui/package.yaml @@ -13,7 +13,7 @@ description: Please see the README on GitHub at = 4.7 && < 5 -- gtk3 >= 0.15.8 +- gtk3 >= 0.15.8 && < 0.15.9 library: source-dirs: src From 71772b6bffc2ee4175b30a250ffc4fcf62816c21 Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Thu, 14 Mar 2024 16:04:26 -0500 Subject: [PATCH 11/16] Add README instructions --- haskell/gtk-gui/README.md | 46 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/haskell/gtk-gui/README.md b/haskell/gtk-gui/README.md index 05b6af2..429f79d 100644 --- a/haskell/gtk-gui/README.md +++ b/haskell/gtk-gui/README.md @@ -1 +1,45 @@ -# gtk-gui +# Creating a GUI application in Haskell with GTK+ + +## Description + +This project serves as a companion codebase for Stack Builder's blog post ["Creating a GUI application in Haskell."](https://www.stackbuilders.com/blog/gui-application/) + +## Requirements + +- Stack 2.11.1 +- Cabal 3.10.2.1 +- GHC 9.4.7 + +## Installation + +For installation instructions of C libraries required by Gtk2Hs and haskell-gi, please refer to the [Gtk2Hs Github Repository](https://github.com/gtk2hs/gtk2hs?tab=readme-ov-file#installing-c-libraries). The installation process may vary depending on your operating system, so make sure to follow the instructions specific to your platform. + +## Building and Running the Project + +1. **Clone the Repository**: Clone this repository to your local machine and navigate to the project directory. + + ```bash + git clone https://github.com/stackbuilders/blog-code.git + cd haskell/gtk-gui/ + ``` + +2. **Install the necessary tools for gtk2hs**: You need to install some tools to build GTK+ bindings. Run the following commands: + + ```bash + stack install alex happy + stack install haskell-gi + stack install gtk2hs-buildtools + stack install + ``` + +3. **Build the Project**: Use Stack to build the project. + + ```bash + stack build + ``` + +4. **Run the Project**: Run the project with the following command: + + ```bash + stack exec gtk-gui-exe + ``` From d14f5362fcdd1e7ce85dc6b13ee74e638103c5d8 Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Thu, 14 Mar 2024 16:32:25 -0500 Subject: [PATCH 12/16] Address Felix comments --- haskell/gtk-gui/README.md | 19 ++----------------- haskell/gtk-gui/package.yaml | 4 ++++ 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/haskell/gtk-gui/README.md b/haskell/gtk-gui/README.md index 429f79d..67c3ed3 100644 --- a/haskell/gtk-gui/README.md +++ b/haskell/gtk-gui/README.md @@ -4,12 +4,6 @@ This project serves as a companion codebase for Stack Builder's blog post ["Creating a GUI application in Haskell."](https://www.stackbuilders.com/blog/gui-application/) -## Requirements - -- Stack 2.11.1 -- Cabal 3.10.2.1 -- GHC 9.4.7 - ## Installation For installation instructions of C libraries required by Gtk2Hs and haskell-gi, please refer to the [Gtk2Hs Github Repository](https://github.com/gtk2hs/gtk2hs?tab=readme-ov-file#installing-c-libraries). The installation process may vary depending on your operating system, so make sure to follow the instructions specific to your platform. @@ -23,22 +17,13 @@ For installation instructions of C libraries required by Gtk2Hs and haskell-gi, cd haskell/gtk-gui/ ``` -2. **Install the necessary tools for gtk2hs**: You need to install some tools to build GTK+ bindings. Run the following commands: - - ```bash - stack install alex happy - stack install haskell-gi - stack install gtk2hs-buildtools - stack install - ``` - -3. **Build the Project**: Use Stack to build the project. +2. **Build the Project**: Use Stack to build the project. ```bash stack build ``` -4. **Run the Project**: Run the project with the following command: +3. **Run the Project**: Run the project with the following command: ```bash stack exec gtk-gui-exe diff --git a/haskell/gtk-gui/package.yaml b/haskell/gtk-gui/package.yaml index c025bdb..fd51719 100644 --- a/haskell/gtk-gui/package.yaml +++ b/haskell/gtk-gui/package.yaml @@ -14,6 +14,10 @@ description: Please see the README on GitHub at = 4.7 && < 5 - gtk3 >= 0.15.8 && < 0.15.9 +- alex +- happy +- haskell-gi +- gtk2hs-buildtools library: source-dirs: src From 1d23d869b6e078180d3efaf48e4c323517e34d91 Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Thu, 14 Mar 2024 16:38:30 -0500 Subject: [PATCH 13/16] Add warning with ARM archs --- haskell/gtk-gui/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/haskell/gtk-gui/README.md b/haskell/gtk-gui/README.md index 67c3ed3..f698311 100644 --- a/haskell/gtk-gui/README.md +++ b/haskell/gtk-gui/README.md @@ -8,6 +8,8 @@ This project serves as a companion codebase for Stack Builder's blog post ["Crea For installation instructions of C libraries required by Gtk2Hs and haskell-gi, please refer to the [Gtk2Hs Github Repository](https://github.com/gtk2hs/gtk2hs?tab=readme-ov-file#installing-c-libraries). The installation process may vary depending on your operating system, so make sure to follow the instructions specific to your platform. +**WARNING**: This setup is incompatible with ARM architectures. + ## Building and Running the Project 1. **Clone the Repository**: Clone this repository to your local machine and navigate to the project directory. From b9290aef584424603d586a31343d493977a12475 Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Thu, 14 Mar 2024 18:59:02 -0500 Subject: [PATCH 14/16] Add build tools bounded dependencies and fix .cabal hpack version --- haskell/gtk-gui/gtk-gui.cabal | 31 +++++++++++++++++++++++++++---- haskell/gtk-gui/package.yaml | 10 ++++++---- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/haskell/gtk-gui/gtk-gui.cabal b/haskell/gtk-gui/gtk-gui.cabal index 8449adc..9634544 100644 --- a/haskell/gtk-gui/gtk-gui.cabal +++ b/haskell/gtk-gui/gtk-gui.cabal @@ -1,15 +1,25 @@ cabal-version: 2.2 --- This file has been generated from package.yaml by hpack version 0.36.0. +-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack name: gtk-gui version: 0.1.0.0 +description: Please see the README on GitHub at +homepage: https://github.com/stackbuilders/blog-code#readme +bug-reports: https://github.com/stackbuilders/blog-code/issues +author: Mark Karpov +maintainer: jgalarza@stackbuilders.com +copyright: 2016 Mark Karpov +license: BSD-3-Clause +build-type: Simple +extra-source-files: + README.md source-repository head type: git - location: https://github.com/githubuser/gtk-gui + location: https://github.com/stackbuilders/blog-code library exposed-modules: @@ -20,9 +30,15 @@ library Paths_gtk_gui hs-source-dirs: src + build-tools: + alex ==3.3.0.* + , happy >=1.20.1.1 && <1.20.2 + build-tool-depends: + gtk2hs-buildtools:gtk2hs-buildtools ==0.13.10.* + , haskell-gi:haskell-gi ==0.26.7.* build-depends: - base >=4.7 && <5, - gtk3 + base >=4.7 && <5 + , gtk3 ==0.15.8.* default-language: Haskell2010 executable gtk-gui-exe @@ -33,7 +49,14 @@ executable gtk-gui-exe Paths_gtk_gui hs-source-dirs: app + build-tools: + alex ==3.3.0.* + , happy >=1.20.1.1 && <1.20.2 + build-tool-depends: + gtk2hs-buildtools:gtk2hs-buildtools ==0.13.10.* + , haskell-gi:haskell-gi ==0.26.7.* build-depends: base >=4.7 && <5 , gtk-gui + , gtk3 ==0.15.8.* default-language: Haskell2010 diff --git a/haskell/gtk-gui/package.yaml b/haskell/gtk-gui/package.yaml index fd51719..22afdfb 100644 --- a/haskell/gtk-gui/package.yaml +++ b/haskell/gtk-gui/package.yaml @@ -14,10 +14,12 @@ description: Please see the README on GitHub at = 4.7 && < 5 - gtk3 >= 0.15.8 && < 0.15.9 -- alex -- happy -- haskell-gi -- gtk2hs-buildtools + +build-tools: +- alex >= 3.3.0 && < 3.3.1 +- happy >= 1.20.1.1 && < 1.20.2 +- haskell-gi >= 0.26.7 && < 0.26.8 +- gtk2hs-buildtools >= 0.13.10 && < 0.13.11 library: source-dirs: src From 3222203917b5db6fd7c9dfc11e1291fedc61a0a3 Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Mon, 18 Mar 2024 10:33:29 -0500 Subject: [PATCH 15/16] Update resolver to lts-22.13 --- haskell/gtk-gui/gtk-gui.cabal | 8 ++++---- haskell/gtk-gui/package.yaml | 4 ++-- haskell/gtk-gui/stack.yaml | 2 +- haskell/gtk-gui/stack.yaml.lock | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/haskell/gtk-gui/gtk-gui.cabal b/haskell/gtk-gui/gtk-gui.cabal index 9634544..7f72d9a 100644 --- a/haskell/gtk-gui/gtk-gui.cabal +++ b/haskell/gtk-gui/gtk-gui.cabal @@ -31,11 +31,11 @@ library hs-source-dirs: src build-tools: - alex ==3.3.0.* + alex >=3.4.0.1 && <3.4.1 , happy >=1.20.1.1 && <1.20.2 build-tool-depends: gtk2hs-buildtools:gtk2hs-buildtools ==0.13.10.* - , haskell-gi:haskell-gi ==0.26.7.* + , haskell-gi:haskell-gi ==0.26.8.* build-depends: base >=4.7 && <5 , gtk3 ==0.15.8.* @@ -50,11 +50,11 @@ executable gtk-gui-exe hs-source-dirs: app build-tools: - alex ==3.3.0.* + alex >=3.4.0.1 && <3.4.1 , happy >=1.20.1.1 && <1.20.2 build-tool-depends: gtk2hs-buildtools:gtk2hs-buildtools ==0.13.10.* - , haskell-gi:haskell-gi ==0.26.7.* + , haskell-gi:haskell-gi ==0.26.8.* build-depends: base >=4.7 && <5 , gtk-gui diff --git a/haskell/gtk-gui/package.yaml b/haskell/gtk-gui/package.yaml index 22afdfb..1e6b1f9 100644 --- a/haskell/gtk-gui/package.yaml +++ b/haskell/gtk-gui/package.yaml @@ -16,9 +16,9 @@ dependencies: - gtk3 >= 0.15.8 && < 0.15.9 build-tools: -- alex >= 3.3.0 && < 3.3.1 +- alex >= 3.4.0.1 && < 3.4.1 - happy >= 1.20.1.1 && < 1.20.2 -- haskell-gi >= 0.26.7 && < 0.26.8 +- haskell-gi >= 0.26.8 && < 0.26.9 - gtk2hs-buildtools >= 0.13.10 && < 0.13.11 library: diff --git a/haskell/gtk-gui/stack.yaml b/haskell/gtk-gui/stack.yaml index c7e4783..61f87be 100644 --- a/haskell/gtk-gui/stack.yaml +++ b/haskell/gtk-gui/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-21.13 +resolver: lts-22.13 packages: - . diff --git a/haskell/gtk-gui/stack.yaml.lock b/haskell/gtk-gui/stack.yaml.lock index d968e8d..fcf6d2a 100644 --- a/haskell/gtk-gui/stack.yaml.lock +++ b/haskell/gtk-gui/stack.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - sha256: 8017c7970c2a8a9510c60cc70ac245d59e0c34eb932b91d37af09fe59855d854 - size: 640038 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/13.yaml - original: lts-21.13 + sha256: 6f0bea3ba5b07360f25bc886e8cff8d847767557a492a6f7f6dcb06e3cc79ee9 + size: 712905 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/13.yaml + original: lts-22.13 From 429a0dfff4f562ec4bc282b6d2530f02899c23ef Mon Sep 17 00:00:00 2001 From: Jorge Galarza Date: Mon, 18 Mar 2024 10:34:10 -0500 Subject: [PATCH 16/16] Remove description --- haskell/gtk-gui/gtk-gui.cabal | 1 - haskell/gtk-gui/package.yaml | 2 -- 2 files changed, 3 deletions(-) diff --git a/haskell/gtk-gui/gtk-gui.cabal b/haskell/gtk-gui/gtk-gui.cabal index 7f72d9a..eb67ee8 100644 --- a/haskell/gtk-gui/gtk-gui.cabal +++ b/haskell/gtk-gui/gtk-gui.cabal @@ -6,7 +6,6 @@ cabal-version: 2.2 name: gtk-gui version: 0.1.0.0 -description: Please see the README on GitHub at homepage: https://github.com/stackbuilders/blog-code#readme bug-reports: https://github.com/stackbuilders/blog-code/issues author: Mark Karpov diff --git a/haskell/gtk-gui/package.yaml b/haskell/gtk-gui/package.yaml index 1e6b1f9..ee90a8f 100644 --- a/haskell/gtk-gui/package.yaml +++ b/haskell/gtk-gui/package.yaml @@ -9,8 +9,6 @@ copyright: "2016 Mark Karpov" extra-source-files: - README.md -description: Please see the README on GitHub at - dependencies: - base >= 4.7 && < 5 - gtk3 >= 0.15.8 && < 0.15.9