我正在编译我正在构建的Yesod站点,以确保在出现此编译器错误时一切正常:
Foundation.hs:164:15: No instance for (Num (Maybe Size)) arising from the literal `140' Possible fix: add an instance declaration for (Num (Maybe Size)) In the `gSize' field of a record In the expression: GravatarOptions {gSize = 140, gDefault = Identicon, gForceDefault = False, gRating = PG} In an equation for `gs': gs = GravatarOptions {gSize = 140, gDefault = Identicon, gForceDefault = False, gRating = PG}
在阅读了haddock文档之后,我知道gSize采用了Maybe Size,并且该Size定义为:
newtype Size = Size Int
如果它有助于任何这里的功能有问题.
import Yesod.Goodies.Gravatar import Data.Text gravatar :: Text -> Text gravatar email = gravatarImg email gs where gs = GravatarOptions { gSize = 140 , gDefault = Identicon , gForceDefault = False , gRating = PG }
我不知道从哪里开始寻找解决方案,有人可以指出我正确的方向吗?感谢您的时间和考虑.
如果gSize
是Maybe Size
,则需要使用其中一个Maybe
构造函数 - 您可以使用Nothing
无值或Just x
指定值.在你的片段中,它应该是Just (Size 140)
,如在
gs = GravatarOptions { gSize = Just (Size 140) , gDefault = Identicon , gForceDefault = False , gRating = PG }