qsort に型注釈をつけると、片方でエラーする。心当たりはある。
qsort.hs:
qsort :: Ord a => [a] -> [a]
qsort [] = []
qsort (x:xs) = qsort smaller ++ [x] ++ qsort larger
where
smaller = [a | a <- xs, a <= x]
larger = [b | b <- xs, b > x]
main :: IO ()
main =
do let helo = "Hello, World!"
putStrLn helo
putStrLn.show $ qsort [3, 1, 4, 1, 5, 9, 2, 6, 5]
putStrLn $ show $ qsort helo
実行結果:
$ ./tcheck testcases/qsort.hs # 1. test-compile source file: testcases/qsort.hs dst dir: /qsort doCompile ... done. implicitPrelude ... done. doCompile ... bunnyc: renSigDoc $ A.Tycon IO CallStack (from HasCallStack): error, called at src/Rename.hs:318:23 in main:Rename
initialTypeConsts に "IO" -> tIO のエントリを加えて解決:
diff --git a/compiler/src/PreDefined.hs b/compiler/src/PreDefined.hs
index 05322ab..004e4ee 100644
--- a/compiler/src/PreDefined.hs
+++ b/compiler/src/PreDefined.hs
@@ -267,5 +267,6 @@ initialTypeConsts =
, ("Char", tChar)
, ("Int", tInt)
, ("Integer", tInteger)
+ , ("IO", tIO)
, ("String", tString)
]
qsort の型注釈なしバージョンは、2016 年 12 月にはすでに動いていた のだから、これの型注釈ありまで3年以上かかったことになる。 ずっと放置してしまってたからなのだが、なんだか感慨深い。