简单问题:为什么不触发重写规则?
{-# RULES "fmap/fmap" forall f g xs. fmap f (fmap g xs) = fmap (f.g) xs #-}
main = do
txt <- fmap head (fmap words (readFile "foo.txt"))
print txt
Run Code Online (Sandbox Code Playgroud)
现在我想写一个提取fun
触发规则,因为它在之前的测试中做了...不是这次.
{-# RULES "fmap/fmap" forall f g xs. fmap f (fmap g xs) = fmap (f.g) xs #-}
fun f g xs = fmap f (fmap g xs)
main = do
txt <- fun (drop 1) words (readFile "foo.txt")
print txt
Run Code Online (Sandbox Code Playgroud)
直到我偶然添加了一个模块名称:
module Main where
{-# RULES …
Run Code Online (Sandbox Code Playgroud) haskell ×1