Levi Campbell
Levi Campbell

Reputation: 6105

No instance for (Num (Maybe Size))

I'm compiling a Yesod site I'm building to make sure everything is working when I get this compiler error:

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}

After reading the haddock documentation, I know that gSize takes a Maybe Size, and that Size is defined as:

newtype Size = Size Int

If it helps any here's the function in question.

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
      }

I'm not sure where to start looking for a solution, could someone please point me in the right direction? Thank you for your time and consideration.

Upvotes: 0

Views: 829

Answers (2)

ony
ony

Reputation: 13253

It says that it can't convert (through Num class) "140" to Maybe Size. You should use gSize = Just (Size 140) I guess

Upvotes: 0

Cat Plus Plus
Cat Plus Plus

Reputation: 129944

If gSize is Maybe Size, then you need to use one of Maybe constructors — you can either use Nothing for no value or Just x for specified value. In your snippet, it should be Just (Size 140), as in

gs = GravatarOptions {
  gSize = Just (Size 140)
  , gDefault = Identicon
  , gForceDefault = False
  , gRating = PG
  }

Upvotes: 5

Related Questions