3
module Main where
import Data.Char
import Control.Monad
import Control.Monad.Trans.Writer
import Control.Applicative
import Data.Monoid
wt :: Int -> Writer Int [String]
wt x=writer(["num:"++ show x],x)
addw::Writer Int [String]
addw = do
a <- wt 2
b <- wt 3
return (a*b)
有2個錯誤:哈斯克爾:沒有實例(含半幺羣智力)時使用作家單子哈斯克爾平臺2013 2.0.0
No instance for (Monoid Int) arising from a do statement
Possible fix: add an instance declaration for (Monoid Int)
In a stmt of a 'do' block: a <- wt 2
In the expression:
do { a <- wt 2;
b <- wt 3;
return (a * b) }
In an equation for `addw':
addw
= do { a <- wt 2;
b <- wt 3;
return (a * b) }
No instance for (Num [String]) arising from a use of `*'
Possible fix: add an instance declaration for (Num [String])
In the first argument of `return', namely `(a * b)'
In a stmt of a 'do' block: return (a * b)
In the expression:
do { a <- wt 2;
b <- wt 3;
return (a * b) }
我的Eclipse 4.4 JUNO使用帶有最新eclipsefp,哈斯克爾平臺2013 2.0.0包括GHC 7.6.3,這個代碼片斷是從學習你Haskell的偉大的良好
它的工作!重量::內部 - >作家[字符串]詮釋 重量X =作家(X,[ 「民:」 ++表明X]) ADDW ::作家[字符串]詮釋 ADDW =做 一個< - 重量2 b < - wt 3 return(a * b) – doofin 2014-09-25 12:02:33