3

Trying using Chart for learning Haskell. Package breaks in building with:

/private/var/folders/m2/qwhdrn_d46z99_3vxchdwn7r0000gn/T/stack5630/Chart-1.9/Graphics/Rendering/Chart/State.hs:102:3: error:
    • No instance for (Control.Monad.Fail.MonadFail Identity)
        arising from a do statement
        with the failable pattern ‘(c : cs)’
    • In a stmt of a 'do' block: (c : cs) <- use shapes
      In the second argument of ‘($)’, namely
        ‘do (c : cs) <- use shapes
            shapes .= cs
            return c’
      In the expression:
        liftCState
          $ do (c : cs) <- use shapes
               shapes .= cs
               return c
    |
102 |   (c:cs) <- use shapes

I am too inexperienced to know how to go about issues like this. Please advise.

duplode
  • 33,731
  • 7
  • 79
  • 150
Madderote
  • 1,107
  • 10
  • 19
  • I'm not familiar with this library, but I'm fairly sure that you can get rid of this error by disabling `MonadFailDesugaring` in GHC (which has only been on by default since 8.6.1) - see [here](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html?highlight=inline#new-monadic-failure-desugaring-mechanism) – Robin Zigmond Mar 26 '19 at 15:08
  • @Robin Zigmond: but that's a language pragma, right? Can I explicitly disable (or change) a pragma from my source file, rather than altering a library? – Madderote Mar 26 '19 at 16:22
  • At the top of your file, {-# LANGUAGE NoMonadFailDesugaring #-} – moonGoose Mar 26 '19 at 16:36
  • @A Tayler: thanks. Overlooked that somehow. – Madderote Mar 26 '19 at 16:53

1 Answers1

2

You have some options to solve that problem. You are trying to do pattern matching in a 'do' block with non-exhaustive patterns. In order to do that:

  • You could disable the MonadFailDesugaring extension. Add {-# LANGUAGE NoMonadFailDesugaring #-} in the top of the file or compile with the flag -XNoMonadFailDesugaring. But this extension cannot be deactivated in GHC 8.8 ot later.

  • You could define or derive a MonadFail instance.

  • You could use the State monad. If a lower monad in the monad transformer stack is an instance of MonadFail, then we can make the highest monad an instance of MonadFail as well.

  • Desist, and perform explicit and exhaustive pattern matching.

source: http://www.fyrbll.me/haskell/language-extensions/monad-fail-desugaring/processed.html