我试图使用OOHaskell实现矩形问题。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
但我得到范围错误。错误消息是
Rectangle.hs:21:38: Not in scope: `widthRef'
Rectangle.hs:22:39: Not in scope: `lengthRef'
Rectangle.hs:23:39: Not in scope: `widthRef'
我该如何解决错误?
谢谢丹尼尔做到了。但现在我得到的错误是:
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))'
什么是*矩形问题*? – Ingo 2012-02-02 11:56:37
问题中有一个简单的矩形和一些基本的功能,对它进行操作.. – 2012-02-02 12:32:51