04/02/15 21:33
>>18
depositだけ実装。
どうしても
> (withdraw 25)
> 75
> (withdraw 25)
> 50
こんなことがしたい、という意味?
それとも、こういう機能があればいいのか?
例:
$ ./a.out
>> Status: [(0,100),(1,1000),(2,300)]
Deposit 1 300
Deposit 2 400
>> Status: [(0,100),(1,1300),(2,700)]
^D
前者なら、
make_withdraw :: IORef Account -> Money -> IO Money
make_withdraw ref money =
do {x <- readIORef ref; writeIORef ref (x - money); readIORef ref}
というのを作っておいて、
ref_account <- newIORef newAccount
let withdraw = make_withdraw ref_account -- :: Money -> IO Money
とする。
後者なら、普通は前者のような設計はしない。