1

I'm trying to build my project and I'm running into a really strange problem. I got my friend to install Haskell with Chocolatey and when he goes to compile my project with cabal build and cabal run project he runs into the following error that I just don't have:

Expr.hs:103:1: error:
    Type applications in patterns are not yet supported
    |
103 | evalVal env val @(HInteger _)      = return $ val
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I assumed that the cabal file would take care of dependencies but obviously not. A cursory search as well proves fruitless because I can't even find another instance of someone having the same error.

I'm not sure if the problem is due to him being on ghc 9.0.1 and cabal 3.4 and I'm on ghc 8.8.3 and cabal 3.2 or if it's due to different operating systems, his being Windows and I OSX.

My worry is that if I upgrade my ghc and cabal versions then I will run into this error and I'll have to reinstall everything which was messy and difficult the first time

Mr.Bloom
  • 343
  • 1
  • 11
  • 1
    I doubt it's cabal but different GHC-versions are usually a problem - I would recommend something like GHCUP to switch versions on demand (or stack) - it's only a hunch but does it go away if your remove the space between `val` and `@(HInteger_ )`? – Random Dev Mar 30 '21 at 11:07
  • 1
    maybe this can help you out too: https://stackoverflow.com/questions/7770100/using-cabal-with-multiple-ghc-versions – Random Dev Mar 30 '21 at 11:08
  • Thank you! I'll take a look at GHCUP and the link! Hopefully that's all there is to it – Mr.Bloom Mar 30 '21 at 11:09
  • please try `val@(HInteger _)` too - it's only a wild guess but maybe they changed syntax there so that as-patterns are without-space and the space indicates the type-application (as the error hints at) - I am a bit excited that it says (not supported **yet**) as I could see some use cases for that - but that is another matter – Random Dev Mar 30 '21 at 11:24
  • 1
    You won't believe it...changing it to `val@(HInteger _)` actually worked. The other thing that had to be done was to install System.Random and then it just worked...thank you so much – Mr.Bloom Mar 30 '21 at 11:26
  • I belive it and I found out why: https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/9.0#whitespace-sensitive-and- – Random Dev Mar 30 '21 at 11:29

1 Answers1

4

It turns out that was a change in GHC 9.0: Whitespace-sensitive !, ~, @, and $

it's the second point there:

f @ x = y

Before: value binding that binds both f and x to y using an as-pattern After: infix function named (@)

To restore the old behavior, remove the leading and trailing whitespace around @, like so:

f@x = x

So if you change it to

evalVal env val@(HInteger _)      = return $ val

it should work for both compilers

Random Dev
  • 51,810
  • 9
  • 92
  • 119