lsmor / snake-fury Goto Github PK
View Code? Open in Web Editor NEWa challenge for Haskell beginners
License: BSD 3-Clause "New" or "Revised" License
a challenge for Haskell beginners
License: BSD 3-Clause "New" or "Revised" License
After applying the fixes from #4 , I tried to run my solution (and then yours to make sure the same problem occurs):
$ cabal run snake-fury -- 10 10 5
This is the output:
Resolving dependencies...
Build profile: -w ghc-9.2.4 -O1
In order, the following will be built (use -v for more details):
- snake-fury-0.1.0.0 (lib) (file src/GameState.hs changed)
- snake-fury-0.1.0.0 (exe:snake-fury) (dependency rebuilt)
./snake-fury.cabal has been changed. Re-configuring with most recently used
options. If this fails, please run configure manually.
Configuring library for snake-fury-0.1.0.0..
Preprocessing library for snake-fury-0.1.0.0..
Building library for snake-fury-0.1.0.0..
[2 of 5] Compiling RenderState ( src/RenderState.hs, /Users/liwoxa/Desktop/Repositories/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.2.4/snake-fury-0.1.0.0/build/RenderState.o, /Users/liwoxa/Desktop/Repositories/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.2.4/snake-fury-0.1.0.0/build/RenderState.dyn_o )
[3 of 5] Compiling GameState ( src/GameState.hs, /Users/liwoxa/Desktop/Repositories/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.2.4/snake-fury-0.1.0.0/build/GameState.o, /Users/liwoxa/Desktop/Repositories/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.2.4/snake-fury-0.1.0.0/build/GameState.dyn_o )
[4 of 5] Compiling EventQueue ( src/EventQueue.hs, /Users/liwoxa/Desktop/Repositories/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.2.4/snake-fury-0.1.0.0/build/EventQueue.o, /Users/liwoxa/Desktop/Repositories/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.2.4/snake-fury-0.1.0.0/build/EventQueue.dyn_o ) [GameState changed]
[5 of 5] Compiling Initialization ( src/Initialization.hs, /Users/liwoxa/Desktop/Repositories/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.2.4/snake-fury-0.1.0.0/build/Initialization.o, /Users/liwoxa/Desktop/Repositories/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.2.4/snake-fury-0.1.0.0/build/Initialization.dyn_o ) [GameState changed]
ld: warning: -undefined dynamic_lookup may not work with chained fixups
./snake-fury.cabal has been changed. Re-configuring with most recently used
options. If this fails, please run configure manually.
Configuring executable 'snake-fury' for snake-fury-0.1.0.0..
Preprocessing executable 'snake-fury' for snake-fury-0.1.0.0..
Building executable 'snake-fury' for snake-fury-0.1.0.0..
[2 of 2] Compiling Main ( app/Main.hs, /Users/liwoxa/Desktop/Repositories/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.2.4/snake-fury-0.1.0.0/x/snake-fury/build/snake-fury/snake-fury-tmp/Main.o )
Linking /Users/liwoxa/Desktop/Repositories/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.2.4/snake-fury-0.1.0.0/x/snake-fury/build/snake-fury/snake-fury ...
Segmentation fault: 11
When running again, I just get:
Up to date
Segmentation fault: 11
Any ideas?
When trying to install with cabal, dependencies resolution fails:
Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: snake-fury-0.1.0.0 (user goal)
[__1] next goal: base (dependency of snake-fury)
[__1] rejecting: base-4.16.3.0/installed-4.16.3.0 (conflict: snake-fury =>
base^>=4.14)
[__1] skipping: base-4.17.0.0, base-4.16.4.0, base-4.16.3.0, base-4.16.2.0,
base-4.16.1.0, base-4.16.0.0, base-4.15.1.0, base-4.15.0.0 (has the same
characteristics that caused the previous version to fail: excluded by
constraint '^>=4.14' from 'snake-fury')
[__1] rejecting: base-4.14.3.0, base-4.14.2.0, base-4.14.1.0, base-4.14.0.0,
base-4.13.0.0, base-4.12.0.0, base-4.11.1.0, base-4.11.0.0, base-4.10.1.0,
base-4.10.0.0, base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0,
base-4.8.0.0, base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1,
base-4.6.0.0, base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0,
base-4.3.1.0, base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0,
base-4.1.0.0, base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from
non-upgradeable package requires installed instance)
[__1] fail (backjumping, conflict set: base, snake-fury)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base, snake-fury
Fixed by removing all of the ^
symbols from the snake-fury.cabal
file and updating the resolver url in stack.yaml
to:
https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/7.yaml
With this I got the VSCode extension to work too.
Hi! Thanks for the challenge! I am rather curious about these tasks.
There is a problem with reading keyboard input on windows in the tui version of the game. The function writeUserInput
is expecting a VT sequence for arrows - yet by default windows terminal (current backend for all windows-native terminals) does not send them, you need to set up stdin properly for that (in case you need more context than you would ever need to know on that subject =), there is an effort to bring brick/vty to windows here: jtdaugherty/vty#251) TLDR: reading interactive user input on windows as VT sequences is a hassle.
Then again, if we put ourselves in a posix-like terminal (e.g. MobaXterm, it does send VT sequences for arrows), we are inviting all possible problems with io-manager =( hReady
behaves rather strangely in that scenario, line buffering is not up to the task, and so on.
I propose to add `wasd/hjkl' as additional aliases for arrows, this does not break the principle of least surprise. And then
hReady
by a CPP pragma in getKey
and warn the user in Readme that arrow keys would not necessarily work on windows.Without hReady
checks all characters will arrive properly one by one, and since a command is just one character, we avoid all parsing troubles.
Other alternatives would be
Cheers!
Implement Manual instances for newtype
in the solution branch as commented in this comment
I am not getting warnings about incomplete pattern matches in refactor 1. I have added the following:
data RenderMessage = RenderBoard DeltaBoard | GameOver | RenderScore Int deriving Show
When I build, this is the output:
snake-fury % cabal build
Warning: Unknown/unsupported 'ghc' version detected (Cabal 3.8.1.0 supports
'ghc' version < 9.6): /Users/jbecca/.ghcup/bin/ghc is version 9.6.2
Build profile: -w ghc-9.6.2 -O1
In order, the following will be built (use -v for more details):
- snake-fury-0.1.0.0 (lib) (first run)
- snake-fury-0.1.0.0 (exe:snake-fury) (first run)
Configuring library for snake-fury-0.1.0.0..
Preprocessing library for snake-fury-0.1.0.0..
Building library for snake-fury-0.1.0.0..
[1 of 5] Compiling Paths_snake_fury ( /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/autogen/Paths_snake_fury.hs, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/Paths_snake_fury.o, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/Paths_snake_fury.dyn_o )
[2 of 5] Compiling RenderState ( src/RenderState.hs, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/RenderState.o, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/RenderState.dyn_o )
[3 of 5] Compiling GameState ( src/GameState.hs, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/GameState.o, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/GameState.dyn_o )
[4 of 5] Compiling EventQueue ( src/EventQueue.hs, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/EventQueue.o, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/EventQueue.dyn_o )
[5 of 5] Compiling Initialization ( src/Initialization.hs, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/Initialization.o, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/build/Initialization.dyn_o )
Configuring executable 'snake-fury' for snake-fury-0.1.0.0..
Preprocessing executable 'snake-fury' for snake-fury-0.1.0.0..
Building executable 'snake-fury' for snake-fury-0.1.0.0..
[1 of 2] Compiling Main ( app/Main.hs, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/x/snake-fury/build/snake-fury/snake-fury-tmp/Main.o )
[2 of 2] Compiling Paths_snake_fury ( /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/x/snake-fury/build/snake-fury/autogen/Paths_snake_fury.hs, /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/x/snake-fury/build/snake-fury/snake-fury-tmp/Paths_snake_fury.o )
[3 of 3] Linking /Users/jbecca/projects/snake-fury/dist-newstyle/build/aarch64-osx/ghc-9.6.2/snake-fury-0.1.0.0/x/snake-fury/build/snake-fury/snake-fury
I have tried adding the following options to the cabal file to force output of these warnings:
ghc-options: -threaded -rtsopts -Wall "-with-rtsopts --io-manager=native" -fwarn-incomplete-patterns -Wincomplete-patterns
Additional info: Here are the versions of cabal, ghc, and ghci I am using
GHC 9.6.2
Cabal 3.10.1.0
As proof that the rest of my code is working and the non exhaustive pattern really exists:
λ> updateRenderState initial_board (RenderScore 5)
*** Exception: /Users/jbecca/projects/snake-fury/src/RenderState.hs:(85,34)-(87,59): Non-exhaustive patterns in case
I also tried with GHC version 9.4.5 and cabal version 3.6.2.0, which also did not warn me. FYI, I tried creating some intentional non-exhaustive matches in other projects and I do get compiler warnings.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.