riordant / Haskell-2D

A simple 2D command line game written in Haskell. Completed for a course in Functional Programming
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

no instance declaration for Monad GameAction #1

Open ghost opened 5 years ago

ghost commented 5 years ago

First of all, sorry if I am building this wrong I just started with Haskell and cabal and everything but when I try to compile it I get


[ 8 of 13] Compiling HaskellGame.GameMonad ( src/HaskellGame/GameMonad.hs, dist/build/haskell-game/haskell-game-tmp/HaskellGame/GameMonad.o )

src/HaskellGame/GameMonad.hs:18:10: error:
    • No instance for (GHC.Base.Applicative GameAction)
        arising from the superclasses of an instance declaration
    • In the instance declaration for ‘Monad GameAction’
   |
18 | instance Monad GameAction where
   |          ^^^^^^^^^^^^^^^^```
keraJLi commented 5 years ago

The build probably fails because the game was written before this. To fix it, add the following to src/HaskellGame/GameMonad.hs:

import Control.Monad (ap, liftM)
instance Functor GameAction where
  fmap = liftM

instance Applicative GameAction where
  pure  = return
  (<*>) = ap

and replace

import Prelude ( Monad(..), ($) )

by

import Prelude ( Monad(..), ($), Applicative (..), Functor (..))