English 中文(简体)
Haskell Others parsing差
原标题:Haskell else parsing error

我对其他投入有大错,但我不知道如何解决。 我对这件事来说仍然是新的。

depot = 
do
putStr ("Enter deposit amount: ")
deAmount <- getLine
let redeAmount = read deAmount
if redeAmount > 0 then 
    let accBal = redeAmount + accBal
    else 
        putStrLn "Please enter amount greater than 0"
问题回答

第一种错误是<代码>do。 (及其之后的一切内容)必须受到削弱。

下一个错误是,直截了当的let accBal = redeAmount + accBal可依此自食。 是否需要在后面加上<代码>。 或必须直接在<代码>do栏内(在if/code>内,do栏内,不适用)。

然而,即使你打上了yn子,也赢得了你们想要的东西。 您可使用<代码>let来重新调配变量。 事实上,你根本不能再分配变量。 如果您确定let的星号,则只会产生新的变量accBal。 这将使旧变量<代码>accBal蒙上阴影。 这一新变量的范围是then-block of the if/code>。 页: 1 页: 1

为了确定你的问题,你需要调整你的逻辑,因此,它并不取决于重新分配的<代码>accBal

我不想再作一番回答,但我认为我是这样说的。

type Balance          = Float               -- The type of the money balance
type TransactionT m a = StateT Balance m a  -- Something that modifies a balance
type Transaction a    = TransactionT IO a   -- Something that interacts with IO
                                            --  *and* modifies balance

-- Request the user to enter a deposit
getDeposit :: Transaction ()
getDeposit = do
 putStr "Enter deposit amount: "  -- You don t need () around the argument

 amountStr <- liftIO getLine  -- This is a consequence of using monad
                              -- transformers

 let amount = read amountStr

 if amount > 0
   then modify (+ amount) -- Update the balance
   else liftIO $ error "Please enter amount greater than 0." -- Raise an
                                                             --  exception

http://learnyouahaskell.com/“rel=“nofollow”http://learnyouahaskell.com/

这里有一些与《守则》有关的章节写道:

Oh, and to make your life easier, Hoogle.





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签