Implement increment function
I am working on this program for better understanding of haskell and state monad. I made a module Rectangle which has data type Rectangle and a function to increment the length of the rectangle. To increment the length i made a function plus. **Could there have been a better way than this plus function?** Also while incrementing i am doing addition with a new rectangle which is logically incorrect. **How to perform the increment in the correct way?**

    {-# LANGUAGE TemplateHaskell, TypeOperators #-}
    module Rectangle(Rectangle(Rectangle),GlobState(GlobState),plus,newGlobState,r1,r2,r3,incr) where

    import Control.Monad.State hiding (modify)
    import Data.Label (mkLabels)
    import Data.Label.Pure ((:->))
    import Data.Label.PureM

    type Length = Int
    type Width = Int

    data Rectangle = Rectangle Length Width deriving (Eq,Read,Show)

    data GlobState = GlobState { _r1 :: Rectangle , _r2 :: Rectangle , _r3 :: Rectangle } deriving Show
    $(mkLabels [''GlobState])

    plus :: Rectangle -> Rectangle -> Rectangle
    plus (Rectangle x z) (Rectangle y w) = Rectangle (x+y) z

    newGlobState:: GlobState
    newGlobState = GlobState { _r1 = Rectangle 0 10, _r2 = Rectangle 0 10, _r3 = Rectangle 0 10}

    incr :: (GlobState :-> Rectangle) -> State GlobState ()
    incr x = modify x (plus (Rectangle 1 10))

I made a new module for the main function.

    module Main where

    import Rectangle
    import Control.Monad.State hiding (modify)
    import Data.Label (mkLabels)
    import Data.Label.Pure ((:->))
    import Data.Label.PureM

    main :: IO ()
    main = do
        let x = flip execState newGlobState $ do
            incr r1
       	    incr r2
            incr r1
            incr r3
            incr r3
        print x

Is there any way in which instead of giving the default width the compiler prompts the user for width? How can i sort of extract one or more rectangle or any attribute(length or breadth) while doing stateful computation?

Implement increment function
===

I am working on this program for better understanding of haskell and state monad. I made a module Rectangle which has data type Rectangle and a function to increment the length of the rectangle. To increment the length i made a function plus. **Could there have been a better way than this plus function?** Also while incrementing i am doing addition with a new rectangle which is logically incorrect. **How to perform the increment in the correct way?**

    {-# LANGUAGE TemplateHaskell, TypeOperators #-}
    module Rectangle(Rectangle(Rectangle),GlobState(GlobState),plus,newGlobState,r1,r2,r3,incr) where

    import Control.Monad.State hiding (modify)
    import Data.Label (mkLabels)
    import Data.Label.Pure ((:->))
    import Data.Label.PureM

    type Length = Int
    type Width = Int

    data Rectangle = Rectangle Length Width deriving (Eq,Read,Show)

    data GlobState = GlobState { _r1 :: Rectangle , _r2 :: Rectangle , _r3 :: Rectangle } deriving Show
    $(mkLabels [''GlobState])

    plus :: Rectangle -> Rectangle -> Rectangle
    plus (Rectangle x z) (Rectangle y w) = Rectangle (x+y) z

    newGlobState:: GlobState
    newGlobState = GlobState { _r1 = Rectangle 0 10, _r2 = Rectangle 0 10, _r3 = Rectangle 0 10}

    incr :: (GlobState :-> Rectangle) -> State GlobState ()
    incr x = modify x (plus (Rectangle 1 10))

I made a new module for the main function.

    module Main where

    import Rectangle
    import Control.Monad.State hiding (modify)
    import Data.Label (mkLabels)
    import Data.Label.Pure ((:->))
    import Data.Label.PureM

    main :: IO ()
    main = do
        let x = flip execState newGlobState $ do
            incr r1
       	    incr r2
            incr r1
            incr r3
            incr r3
        print x

Is there any way in which instead of giving the default width the compiler prompts the user for width? How can i sort of extract one or more rectangle or any attribute(length or breadth) while doing stateful computation?
