Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7367999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:36:33+00:00 2026-05-29T03:36:33+00:00

I have tried to implement the rectangle problem using OOHaskell. {-# LANGUAGE EmptyDataDecls, DeriveDataTypeable,

  • 0

I have tried to implement the rectangle problem using OOHaskell.

{-# LANGUAGE EmptyDataDecls, DeriveDataTypeable, TemplateHaskell #-}
{-# OPTIONS_GHC -fcontext-stack=100 #-}

module Rectangle where

import OOHaskell

$(label "getLength")
$(label "getWidth")
$(label "incr")
$(label "lengthenBy")
$(label "setLength")
$(label "setWidth")

rectangle length width self
          = do
             lengthRef <- newIORef value
              widthRef <- newIORef width
              return $
              getLength   .=. readIORef lengthRef
          .*. getWidth    .=. readIORef widthRef
          .*. setLength   .=. writeIORef lengthRef
          .*. setWidth    .=. writeIORef widthRef
          .*. lengthenBy  .=. (\dv ->
                 do
                   value <- self # getValue
                   (self # setValue) (value + dv))
          .*. incr        .=. (self # (lengthenBy 1))
          .*. emptyRecord

But i am getting the scope error. The error meassage is

 Rectangle.hs:21:38: Not in scope: `widthRef'
 Rectangle.hs:22:39: Not in scope: `lengthRef'
 Rectangle.hs:23:39: Not in scope: `widthRef'

How can i resolve the error?

Thanks Daniel done that. But now the error i am getting is:

The function `lengthenBy' is applied to one argument,
but its type `Proxy LengthenBy' has none
In the second argument of `(#)', namely `(lengthenBy 1)'
In the second argument of `(.=.)', namely `(self # (lengthenBy 1))'
In the first argument of `(.*.)', namely
  `incr .=. (self # (lengthenBy 1))'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:36:33+00:00Added an answer on May 29, 2026 at 3:36 am

    Fix your indentation:

          = do
             lengthRef <- newIORef value
              widthRef <- newIORef width
    

    the ‘l’ of lengthRef and the ‘w’ of widthRef must be in the same column.

    As it stands, it is parsed as

    = do lengthRef <- newIORef value widthRef <- newIORef ...
    

    However, I think that should produce a parse error and not reach the ‘not in scope’ phase. So I guess that’s not in your actual code but a paste-glitch here.

    Then:

              return $
              getLength   .=. readIORef lengthRef
          .*. getWidth    .=. readIORef widthRef
          .*. setLength   .=. writeIORef lengthRef
          .*. setWidth    .=. writeIORef widthRef
          .*. lengthenBy  .=. (\dv ->
                 do
                   value <- self # getValue
                   (self # setValue) (value + dv))
          .*. incr        .=. (self # (lengthenBy 1))
          .*. emptyRecord
    

    breaks it, the .*. is indented less than the do-block indentation, so it’s parsed as

    (do ...
        getLength .=. readIORef lengthRef) .*. getWidth .=. ...
    

    Indent the stuff you want to go inside the return farther than the enclosing do-block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to implement the Head First Duck problem with Startegy. I am
i have tried to implement following code #include <iostream> #include <bitset> using namespace std;
I have tried to implement progress reporting using a soap extension as described at
I have tried to implement Stack Overflow question C++ Data Member Alignment and Array Packing
I have tried to implement a program using sockets in Ubuntu 10.04. Here is
I have been looking around for solutions, and tried to implement what is often
I have tried to find how to create DLL-s on linux using google, but
i have tried implement two methods recursive and dynamic method and both took 0
I have tried to implement binary insertion sort algorithm. Here is my code: public
I have tried to implement the puts function.It in actual returns a value but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.