Questo piccolo haskell code snippet provoca ghc di non interrompere durante la compilazione:Piccolo frammento di codice provoca ghc di non terminare
{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -O2 #-}
import qualified Data.Vector.Unboxed.Mutable as MV
import Data.Vector.Unboxed ((!))
import qualified Data.Vector.Unboxed as V
import Control.Monad (forM_)
similar :: V.Vector Char -> Int
similar v = l + sum (map (similar' 1 1) checks)
where
(l,checks) = let h = V.head v in V.foldl'
(\(i,is) c -> if c == h then (i+1,i:is) else (i+1,is)) (1,[]) (V.tail v)
similar' !r !n !i = if i < l-1 && v!(n) == v!(i+1) then similar' (r+1) (n+1) (i+1)
else r
main :: IO()
main = do
n <- getLine
v <- MV.replicate (read n) 0
forM_ [1..read n] $ \n' -> do
v' <- getLine
MV.unsafeWrite v (n'-1) (similar . V.fromList $ v')
V.unsafeFreeze v >>= V.mapM_ print
ho cercato ghc 7.4.1 e 7.6.1 ed entrambi non terminare. Il codice ha funzionato bene quando ho usato ByteString
s invece di Vector
s. Si tratta di un problema di ghc o di un problema di libreria? o c'è un problema da qualche parte nel mio codice?
Se il compilatore si arresta in modo anomalo, è colpa del compilatore. –