Error when implementing a typeclass instance for a function

64 Views Asked by At

From Hutton's https://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf

class HuttonMonad m where
    result :: a -> m a
    bind   :: m a -> (a -> m b) -> m b

type Parser a = String -> [(a, String)]

instance HuttonMonad Parser where
    result v = \input -> [(v, input)]
    bind p f = \inp -> concat  [ f v out | (v, out) <- p inp]

ghc brings up the following error message

[1 of 2] Compiling Main             ( test.hs, test.o ) [Source file changed]

test.hs:7:10: error: [GHC-27346]
    • The type synonym ‘Parser’ should have 1 argument, but has been given none
    • In the instance declaration for ‘HuttonMonad Parser’
  |
7 | instance HuttonMonad Parser where
  |          ^^^^^^^^^^^^^^^^^^

I assume Haskell has changed over the years, but how do I implement HuttonMonad for the Parser type?

(Note: I am aware of parsec et. al. My goal here is to follow the linked PDF)

0

There are 0 best solutions below