module Main where
newtype Rec a b = Rec {deRec :: Rec a b -> a}
infixl 1 >|>
infixl 1 <|<
(>|>) = Rec
(<|<) (Rec x) = x
fix f = (\x -> f (x <|< x)) (Rec (\x -> f (x <|< x)))
factorial = fix (\f x -> if x<=1 then 1 else x*f(x-1))
main = do
x <- getLine
putStrLn (show (factorial (read x)))
Run Code Online (Sandbox Code Playgroud)
GHC回应:
ghc: panic! (the 'impossible' happened)
(GHC version 7.6.3 for x86_64-apple-darwin):
Simplifier ticks exhausted
When trying UnfoldingDone a_sMx{v} [lid]
To increase the limit, use -fsimpl-tick-factor=N (default 100)
If you need to do this, let GHC HQ know, and what factor you needed
To see detailed counts use -ddump-simpl-stats
Total ticks: 7121
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
Run Code Online (Sandbox Code Playgroud)
怎么了?
Gab*_*lez 13
我认为这与已知的bug有关.见ghc手册第14.2节:
http://www.haskell.org/ghc/docs/7.6.2/html/users_guide/bugs.html
我将在这里重现相关部分:
使用标准方法通过数据类型编码递归,可以将GHC的inliner说服为非终止:
data U = MkU (U -> Bool)
russel :: U -> Bool
russel u@(MkU p) = not $ p u
x :: Bool
x = russel (MkU russel)
Run Code Online (Sandbox Code Playgroud)
我们从来没有发现过另一类程序,除了这个程序之外,它使GHC发散,修复问题会给每次编译带来额外的开销.所以bug仍然是不固定的.GHC内衬的秘密有更多背景.
换句话说,当您在负位置(即函数的参数)使用递归时会出现此错误.从手册中可以看出,他们无意解决这个问题.