Search code examples
haskellhappstack

Newbie question on syntax and type signature in Haskell/HappStack


Why is it that I can't do

z = x?

but I can do this?

y s = x s

I'm a Haskell newbie This is what I've been trying in GHCi:

Prelude> import Happstack.Server
Prelude Happstack.Server> let x s = ok $ toResponse $ "Some string"
Prelude Happstack.Server> :t x
x :: FilterMonad Response m => t -> m Response

Prelude Happstack.Server> let y s = x s
Prelude Happstack.Server> :t y
y :: FilterMonad Response m => t -> m Response

Prelude Happstack.Server> let z = x
<interactive>:1:9:
    No instance for (FilterMonad Response m0)
      arising from a use of `x'

Solution

  • Looks like another case of the monomorphism restriction.

    You can either include the argument explicitly, i.e. y s = x s, include an explicit type signature, or run GHCi with -XNoMonomorphismRestriction.