Home > Enterprise >  getting an error while changing a record value in Haskell
getting an error while changing a record value in Haskell

Time:10-14

move :: Board -> Direction -> Board
move board direction = board {selector = (fst (selector board)   fst direction, snd (selector board)   snd direction)}

this is what I wrote as code but I get this error message when I try to use "move":

<interactive>:91:1: error:
    * No instance for (Show Board) arising from a use of `print'
    * In a stmt of an interactive GHCi command: print it`

I understand that I can't print "initBoard" but I don't see what I'm doing wrong here.

CodePudding user response:

In GHCi, if you do:

ghci> board1 = move board0 dir

You will be able to use your move function without error. But if you evaluate an expression whose type isn't an instance of Show, then you get the error:

ghci> move board0 dir

Same goes for any other type, like functions:

ghci> add1 = (1  )
ghci> add1 2
3
ghci> add1

<interactive>:5:1: error:
    • No instance for (Show (Integer -> Integer))
        arising from a use of ‘print’
        (maybe you haven't applied a function to enough arguments?)
    • In a stmt of an interactive GHCi command: print it
  • Related