From 21242ecbfa3fcbb6b054e7d8ca777b3201b90cec Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 18 Jul 2024 19:06:17 -0400 Subject: [PATCH] lensify `AppState` --- hamming.cabal | 3 +++ package.yaml | 1 + src/Hamming/App/Types.hs | 13 +++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hamming.cabal b/hamming.cabal index cb55132..eb431a0 100644 --- a/hamming.cabal +++ b/hamming.cabal @@ -34,6 +34,7 @@ library build-depends: base >=4.7 && <5 , brick >=2.1.1 && <2.2 + , microlens-th >=0.4.3.15 && <0.5 , mtl >=2.3.1 && <2.4 default-language: Haskell2010 @@ -50,6 +51,7 @@ executable hamming base >=4.7 && <5 , brick >=2.1.1 && <2.2 , hamming + , microlens-th >=0.4.3.15 && <0.5 , mtl >=2.3.1 && <2.4 default-language: Haskell2010 @@ -70,5 +72,6 @@ test-suite hamming-test , brick >=2.1.1 && <2.2 , hamming , hspec >=2.11.9 && <2.12 + , microlens-th >=0.4.3.15 && <0.5 , mtl >=2.3.1 && <2.4 default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index ce19b22..f3b1e3f 100644 --- a/package.yaml +++ b/package.yaml @@ -21,6 +21,7 @@ description: Please see the README on GitHub at = 4.7 && < 5 - brick >= 2.1.1 && < 2.2 +- microlens-th >= 0.4.3.15 && < 0.5 - mtl >= 2.3.1 && < 2.4 ghc-options: diff --git a/src/Hamming/App/Types.hs b/src/Hamming/App/Types.hs index 50ad2d9..bdd725e 100644 --- a/src/Hamming/App/Types.hs +++ b/src/Hamming/App/Types.hs @@ -24,15 +24,24 @@ License along with this program. If not, see |-} -module Hamming.App.Types (AppState (..), initialState) where +{-# LANGUAGE TemplateHaskell #-} + +module Hamming.App.Types ( + AppState (..), + hammingCode, + initialState + ) where import Data.Word (Word16) +import Lens.Micro.TH (makeLenses) -- | The main state of the application data AppState = AppState - { hammingCode :: Word16 + { _hammingCode :: Word16 } +makeLenses ''AppState + -- | Initial application state initialState :: AppState initialState = AppState 0