Currying 3 Arguments in Haskell

前端 未结 3 688
说谎
说谎 2020-11-28 12:35

I\'m having trouble with currying a function to remove three arguments in Haskell.

Disclaimer: Not Coursework, I was asked this question by someone struggling with

3条回答
  •  一整个雨季
    2020-11-28 12:59

    funcB = ((!!) .) . iterate . funcA
    

    I think you did all the hard work, and there was just one tiny step left.

    You can indeed do this automatically with pointfree. See the HaskellWiki page

    As it says in the github readme, once you've installed it, you can edit your ghci.conf or .ghci file with the line

    :def pf \str -> return $ ":! pointfree \"" ++ str ++ "\""
    

    and then in ghci when you type

    :pf funcB as = (!!) . (iterate . funcA) as
    

    or even

    :pf funcB as str n = iterate (funcA as) str !! n
    

    you get

    funcB = ((!!) .) . iterate . funcA
    

提交回复
热议问题