Home > Net >  Why Am I Getting No instance for (Num (m0 b0)) arising from a use of ‘it’
Why Am I Getting No instance for (Num (m0 b0)) arising from a use of ‘it’

Time:02-25

I am reading "What I Wish I Knew When Learning Haskell", and on page 72 there is this statement:

The first law is that when return a is passed through (>>=) into a function f, this expression is exactly equivalent to f.

So I am trying to do this:

return 3 >>= (  1)

and I get

    No instance for (Num (m0 b0)) arising from a use of ‘it’
    In a stmt of an interactive GHCi command: print it

What am I doing wrong?

CodePudding user response:

The return 3 >>= ( 1) is equivalent to 3 1, but the type of 3 1 should be a Monad m => m a: (>>=) :: Monad m => m a -> (a -> m b) -> m b requires that the right operand is a function that takes an a and returns an m b. It thus looks for a way to see this as a Number, but that does not make much sense.

You can for example work with print :: Show a => a -> IO () to print the result, so:

return 3 >>= print . ( 1)
  • Related