ghc panic on simple program
I am experimenting with Haskell, and am attempting to write a simple maze solver. ghci gives meaningful errors for it, and doesn't crash, but ghc gives
~/haskell/course$ ghc tiltmaze.hs
[1 of 1] Compiling Main ( tiltmaze.hs, tiltmaze.o )
ghc: panic! (the 'impossible' happened)
(GHC version 8.0.2 for x86_64-unknown-linux):
initTc: unsolved constraints
WC {wc_insol =
[W] m'_a5Wy :: t_a5Wx[tau:1] (CHoleCan: m')
[W] sx'_a5WB :: t_a5WA[tau:1] (CHoleCan: sx')
[W] sy'_a5WE :: t_a5WD[tau:1] (CHoleCan: sy')}
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
The code is:
import Data.Sequence as Sequence
-- A maze is a grid of empty cells and walls
-- true means wall
data Maze = Seq (Seq Bool)
data Direction = North | South | East | West
directions = [North, South, East, West]
step :: Direction -> Int -> Int -> (Int, Int)
step d x y
| North = (x, y-1)
| South = (x, y+1)
| East = (x+1, y)
| West = (x-1, y)
solve :: Maze -> Int -> Int -> Int -> Int -> Bool
solve m sx sy tx ty
| sx == tx && sy == ty = True
| otherwise =
let solved m x y d
| x' < 0 = False
| y' < 0 = False
| x' >= Sequence.length m = False
| y' >= Sequence.length $ m `index` x' = False
| not ((m `index` x') `index` y') = False
| otherwise = solve m' x' y' tx ty
where (x', y') = step d
m' = update y False (m `index` x)
in any (solved m' sx' sy') directions
Trac metadata
Trac field | Value |
---|---|
Version | 8.2.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |