(感谢Rein Henrichs和Carsten关于上一篇文章的建议 - 现已删除。)
即使以下在Haskell中不常见,以这种方式定义前向函数组合运算符和反向应用程序运算符是否存在效率低下或不足之处?
> let (?) f g = \x -> g (f x) -- forward function composition operator
> :t (+3) ? (*4)
> (+3) ? (*4) :: Num t => t -> t
> let x ?? f = f x -- reverse application operator
-- For those who have the Haskell Platform 2014.2.0.0 with GHCi version 7.8.3, so Data.Function (&) :: a -> (a -> b) -> b is unavailable
- 示例
> "roma" ?? (reverse ? map toUpper ? concatMap (\c -> [c,' ']) ? (++ "- ") ? repeat ? take 3? concat ? (\cs -> take (length cs - 3) cs) ? putStrLn)
> A M O R - A M O R - A M O R
> :t (reverse ? map toUpper ? concatMap (\c -> [c,' ']) ? (++ "- ") ? repeat ? take 3? concat ? (\cs -> take (length cs - 3) cs) ? putStrLn)
> reverse ? ... ?putStrLn :: [Char] -> IO ()
答案 0 :(得分:3)
我不认为这种方法效率低下。但请注意,使用# create your data-only containers (safe to run several times)
crane provision data # needed when building from Dockerfile
crane create data
# build/start your app.
crane lift -r # similar to docker-compose build && docker compose up
# Force re-create off your data-only containers...
crane create --recreate data
和flip
上的.
可以更轻松地定义您的功能:
$
还要确保不要忘记运算符上的(?) = flip (.)
(??) = flip ($)
声明(最好是与非反转版本一致的声明)。
P.S。我认为名称infixl
和?
对于它们的含义非常不直观。