代码之家  ›  专栏  ›  技术社区  ›  Michel

C++的std::bind2nd是否有内置的Haskell等价物?

  •  4
  • Michel  · 技术社区  · 17 年前

    bind2nd :: (a -> b -> c) -> b -> a -> c
    bind2nd f b = \a -> f a b
    
    foo :: Int -> Bool -> String
    foo n b | b = show n
            | otherwise = "blabla"
    
    alwaysN :: Int -> String
    alwaysN = bind2nd foo True
    
    1 回复  |  直到 17 年前
        1
  •  15
  •   ShreevatsaR    17 年前

    它被称为 flip .

    例子:

    Prelude> flip (-) 2 3
    1
    

    为了将来参考,只需搜索即可找到 Hoogle 对于您问题中的类型签名,即 (a -> b -> c) -> b -> a -> c . :-)

    推荐文章