小编zud*_*dov的帖子

如何使fmap重写规则触发?

简单问题:为什么不触发重写规则?

{-# 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

13
推荐指数
1
解决办法
343
查看次数

标签 统计

haskell ×1