I'm learning haskell, and I'm trying to rewrite a function using composition only
Here's the function I'm trying to refactor:
ceilingDiv a b = ceiling (a / b)
So far I managed to make it work using curry and uncurry but it feels dirty:
ceilingDiv = curry $ ceiling . uncurry (/)
Is there any way to do this more cleanly? I was thinking ceiling . div, but it doesn't work because (/) returns a function and ceiling takes a Double as its argument.
There's a fun site called https://pointfree.io - it provides a solution to your problem like this: ceilingDiv = (ceiling .) . (/). It looks ugly because point-free composition with multiple arguments is a pain. Sometimes it's achieved by using . sections like here, sometimes by using an Applicative instance of functions and the <*> operator.
I think your solution with curry-uncurry is nice. It deals with passing multiple arguments by wrapping them into one tuple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With